|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/styleeditor.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/gutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/filefield.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "historytypes.h"
|
|
shun-iwasawa |
ad7711 |
#include "toonzqt/lutcalibrator.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/stylemanager.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/toonzfolders.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/cleanupcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/palettecontroller.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/imagestyles.h"
|
|
Shinya Kitaoka |
120a6e |
#include "toonz/txshsimplelevel.h" //iwsw
|
|
Shinya Kitaoka |
120a6e |
#include "toonz/levelproperties.h" //iwsw
|
|
|
bf1d82 |
#include "toonz/mypaintbrushstyle.h"
|
|
shun-iwasawa |
388550 |
#include "toonz/preferences.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfiletype.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tlevel_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tropcm.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorrenderdata.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsimplecolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorbrushstyle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qhboxlayout></qhboxlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qvboxlayout></qvboxlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qgridlayout></qgridlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpainter></qpainter>
|
|
Toshihiro Shimizu |
890ddd |
#include <qbuttongroup></qbuttongroup>
|
|
Toshihiro Shimizu |
890ddd |
#include <qmouseevent></qmouseevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <qlabel></qlabel>
|
|
Toshihiro Shimizu |
890ddd |
#include <qcheckbox></qcheckbox>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpushbutton></qpushbutton>
|
|
Toshihiro Shimizu |
890ddd |
#include <qradiobutton></qradiobutton>
|
|
Toshihiro Shimizu |
890ddd |
#include <qcombobox></qcombobox>
|
|
Toshihiro Shimizu |
890ddd |
#include <qscrollarea></qscrollarea>
|
|
Toshihiro Shimizu |
890ddd |
#include <qstackedwidget></qstackedwidget>
|
|
Toshihiro Shimizu |
890ddd |
#include <qstyleoptionslider></qstyleoptionslider>
|
|
Toshihiro Shimizu |
890ddd |
#include <qtooltip></qtooltip>
|
|
Toshihiro Shimizu |
890ddd |
#include <qsplitter></qsplitter>
|
|
Jeremy Bullock |
0a2e55 |
#include <qmenu></qmenu>
|
|
shun-iwasawa |
ad7711 |
#include <qopenglframebufferobject></qopenglframebufferobject>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace StyleEditorGUI;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// UndoPaletteChange definition
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class UndoPaletteChange final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int m_styleId;
|
|
Shinya Kitaoka |
120a6e |
const TColorStyleP m_oldColor, m_newColor;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::wstring m_oldName, m_newName;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool m_oldEditedFlag, m_newEditedFlag;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int m_frame;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
UndoPaletteChange(TPaletteHandle *paletteHandle, int styleId,
|
|
Shinya Kitaoka |
120a6e |
const TColorStyle &oldColor, const TColorStyle &newColor)
|
|
Shinya Kitaoka |
120a6e |
: m_paletteHandle(paletteHandle)
|
|
Shinya Kitaoka |
120a6e |
, m_palette(paletteHandle->getPalette())
|
|
Shinya Kitaoka |
120a6e |
, m_styleId(styleId)
|
|
Shinya Kitaoka |
120a6e |
, m_oldColor(oldColor.clone())
|
|
Shinya Kitaoka |
120a6e |
, m_newColor(newColor.clone())
|
|
Shinya Kitaoka |
120a6e |
, m_oldName(oldColor.getName())
|
|
Shinya Kitaoka |
120a6e |
, m_newName(newColor.getName())
|
|
Shinya Kitaoka |
120a6e |
, m_frame(m_palette->getFrame())
|
|
Shinya Kitaoka |
120a6e |
, m_oldEditedFlag(oldColor.getIsEditedFlag())
|
|
Shinya Kitaoka |
120a6e |
, m_newEditedFlag(newColor.getIsEditedFlag()) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
m_palette->setStyle(m_styleId, m_oldColor->clone());
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(m_styleId)->setIsEditedFlag(m_oldEditedFlag);
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(m_styleId)->setName(m_oldName);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_palette->isKeyframe(m_styleId, m_frame))
|
|
Shinya Kitaoka |
120a6e |
m_palette->setKeyframe(m_styleId, m_frame);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// don't change the dirty flag. because m_palette may not the current
|
|
Shinya Kitaoka |
120a6e |
// palette when undo executed
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
m_palette->setStyle(m_styleId, m_newColor->clone());
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(m_styleId)->setIsEditedFlag(m_newEditedFlag);
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(m_styleId)->setName(m_newName);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_palette->isKeyframe(m_styleId, m_frame))
|
|
Shinya Kitaoka |
120a6e |
m_palette->setKeyframe(m_styleId, m_frame);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// don't change the dirty flag. because m_palette may not the current
|
|
Shinya Kitaoka |
120a6e |
// palette when undo executed
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// imprecise - depends on the style
|
|
Shinya Kitaoka |
38fd86 |
int getSize() const override {
|
|
Shinya Kitaoka |
38fd86 |
return sizeof(*this) + 2 * sizeof(TColorStyle *);
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr(
|
|
Shinya Kitaoka |
120a6e |
"Change Style Palette : %1 Style#%2 [R%3 G%4 B%5] -> [R%6 "
|
|
Shinya Kitaoka |
120a6e |
"G%7 B%8]")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()))
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::number(m_styleId))
|
|
Shinya Kitaoka |
120a6e |
.arg(m_oldColor->getMainColor().r)
|
|
Shinya Kitaoka |
120a6e |
.arg(m_oldColor->getMainColor().g)
|
|
Shinya Kitaoka |
120a6e |
.arg(m_oldColor->getMainColor().b)
|
|
Shinya Kitaoka |
120a6e |
.arg(m_newColor->getMainColor().r)
|
|
Shinya Kitaoka |
120a6e |
.arg(m_newColor->getMainColor().g)
|
|
Shinya Kitaoka |
120a6e |
.arg(m_newColor->getMainColor().b);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ColorModel implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
const int ChannelMaxValues[] = {255, 255, 255, 255, 359, 100, 100};
|
|
Shinya Kitaoka |
120a6e |
const int ChannelPairMaxValues[][2] = {{255, 255}, {255, 255}, {255, 255},
|
|
Shinya Kitaoka |
120a6e |
{255, 255}, {100, 100}, {359, 100},
|
|
Shinya Kitaoka |
120a6e |
{359, 100}};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ColorModel::ColorModel() { memset(m_channels, 0, sizeof m_channels); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorModel::rgb2hsv() {
|
|
Shinya Kitaoka |
120a6e |
QColor converter(m_channels[0], m_channels[1], m_channels[2]);
|
|
Shinya Kitaoka |
120a6e |
m_channels[4] =
|
|
Shinya Kitaoka |
120a6e |
std::max(converter.hue(), 0); // hue() ritorna -1 per colori acromatici
|
|
Shinya Kitaoka |
120a6e |
m_channels[5] = converter.saturation() * 100 / 255;
|
|
Shinya Kitaoka |
120a6e |
m_channels[6] = converter.value() * 100 / 255;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorModel::hsv2rgb() {
|
|
Shinya Kitaoka |
120a6e |
QColor converter = QColor::fromHsv(m_channels[4], m_channels[5] * 255 / 100,
|
|
Shinya Kitaoka |
120a6e |
m_channels[6] * 255 / 100);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_channels[0] = converter.red();
|
|
Shinya Kitaoka |
120a6e |
m_channels[1] = converter.green();
|
|
Shinya Kitaoka |
120a6e |
m_channels[2] = converter.blue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorModel::setTPixel(const TPixel32 &pix) {
|
|
Shinya Kitaoka |
120a6e |
QColor color(pix.r, pix.g, pix.b, pix.m);
|
|
Shinya Kitaoka |
120a6e |
m_channels[0] = color.red();
|
|
Shinya Kitaoka |
120a6e |
m_channels[1] = color.green();
|
|
Shinya Kitaoka |
120a6e |
m_channels[2] = color.blue();
|
|
Shinya Kitaoka |
120a6e |
m_channels[3] = color.alpha();
|
|
Shinya Kitaoka |
120a6e |
m_channels[4] =
|
|
Shinya Kitaoka |
120a6e |
std::max(color.hue(), 0); // hue() ritorna -1 per colori acromatici
|
|
Shinya Kitaoka |
120a6e |
m_channels[5] = color.saturation() * 100 / 255;
|
|
Shinya Kitaoka |
120a6e |
m_channels[6] = color.value() * 100 / 255;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPixel32 ColorModel::getTPixel() const {
|
|
Shinya Kitaoka |
120a6e |
return TPixel32(m_channels[0], m_channels[1], m_channels[2], m_channels[3]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorModel::setValue(ColorChannel channel, int value) {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= (int)channel && (int)channel < 7);
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= value && value <= ChannelMaxValues[channel]);
|
|
Shinya Kitaoka |
120a6e |
m_channels[(int)channel] = value;
|
|
Shinya Kitaoka |
120a6e |
if (channel >= eHue)
|
|
Shinya Kitaoka |
120a6e |
hsv2rgb();
|
|
Shinya Kitaoka |
120a6e |
else if (channel <= eBlue)
|
|
Shinya Kitaoka |
120a6e |
rgb2hsv();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorModel::setValues(ColorChannel channel, int v, int u) {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= (int)channel && (int)channel < 7);
|
|
Shinya Kitaoka |
120a6e |
switch (channel) {
|
|
Shinya Kitaoka |
120a6e |
case eRed:
|
|
Shinya Kitaoka |
120a6e |
setValue(eGreen, v);
|
|
Shinya Kitaoka |
120a6e |
setValue(eBlue, u);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eGreen:
|
|
Shinya Kitaoka |
120a6e |
setValue(eRed, v);
|
|
Shinya Kitaoka |
120a6e |
setValue(eBlue, u);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eBlue:
|
|
Shinya Kitaoka |
120a6e |
setValue(eRed, v);
|
|
Shinya Kitaoka |
120a6e |
setValue(eGreen, u);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eHue:
|
|
Shinya Kitaoka |
120a6e |
setValue(eSaturation, v);
|
|
Shinya Kitaoka |
120a6e |
setValue(eValue, u);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eSaturation:
|
|
Shinya Kitaoka |
120a6e |
setValue(eHue, v);
|
|
Shinya Kitaoka |
120a6e |
setValue(eValue, u);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eValue:
|
|
Shinya Kitaoka |
120a6e |
setValue(eHue, v);
|
|
Shinya Kitaoka |
120a6e |
setValue(eSaturation, u);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Rozhuk Ivan |
823a31 |
default:
|
|
Rozhuk Ivan |
823a31 |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int ColorModel::getValue(ColorChannel channel) const {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= (int)channel && (int)channel < 7);
|
|
Shinya Kitaoka |
120a6e |
return m_channels[(int)channel];
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void ColorModel::getValues(ColorChannel channel, int &u, int &v) {
|
|
Shinya Kitaoka |
120a6e |
switch (channel) {
|
|
Shinya Kitaoka |
120a6e |
case eRed:
|
|
Shinya Kitaoka |
120a6e |
u = getValue(eGreen);
|
|
Shinya Kitaoka |
120a6e |
v = getValue(eBlue);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eGreen:
|
|
Shinya Kitaoka |
120a6e |
u = getValue(eRed);
|
|
Shinya Kitaoka |
120a6e |
v = getValue(eBlue);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eBlue:
|
|
Shinya Kitaoka |
120a6e |
u = getValue(eRed);
|
|
Shinya Kitaoka |
120a6e |
v = getValue(eGreen);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eHue:
|
|
Shinya Kitaoka |
120a6e |
u = getValue(eSaturation);
|
|
Shinya Kitaoka |
120a6e |
v = getValue(eValue);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eSaturation:
|
|
Shinya Kitaoka |
120a6e |
u = getValue(eHue);
|
|
Shinya Kitaoka |
120a6e |
v = getValue(eValue);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case eValue:
|
|
Shinya Kitaoka |
120a6e |
u = getValue(eHue);
|
|
Shinya Kitaoka |
120a6e |
v = getValue(eSaturation);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Rozhuk Ivan |
823a31 |
default:
|
|
Rozhuk Ivan |
823a31 |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class RedShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RedShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int value) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor(value, m_color.g(), m_color.b()).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class GreenShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
GreenShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int value) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor(m_color.r(), value, m_color.b()).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class BlueShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
BlueShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int value) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor(m_color.r(), m_color.g(), value).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class AlphaShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
AlphaShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int value) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor(m_color.r(), m_color.g(), m_color.b(), value).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class HueShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
HueShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int value) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor::fromHsv(359 * value / 255, m_color.s() * 255 / 100,
|
|
Shinya Kitaoka |
120a6e |
m_color.v() * 255 / 100)
|
|
Shinya Kitaoka |
120a6e |
.rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class SaturationShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SaturationShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int value) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor::fromHsv(m_color.h(), value, m_color.v() * 255 / 100).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class ValueShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
ValueShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int value) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor::fromHsv(m_color.h(), m_color.s() * 255 / 100, value).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class RedGreenShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RedGreenShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int u, int v) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor(u, v, m_color.b()).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class RedBlueShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RedBlueShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int u, int v) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor(u, m_color.g(), v).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class GreenBlueShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
GreenBlueShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int u, int v) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor(m_color.r(), u, v).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class SaturationValueShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SaturationValueShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int u, int v) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor::fromHsv(m_color.h(), u, v).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class HueValueShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
HueValueShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int u, int v) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor::fromHsv(359 * u / 255, m_color.s() * 255 / 100, v).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class HueSaturationShadeMaker {
|
|
Shinya Kitaoka |
120a6e |
const ColorModel &m_color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
HueSaturationShadeMaker(const ColorModel &color) : m_color(color) {}
|
|
Shinya Kitaoka |
120a6e |
inline QRgb shade(int u, int v) const {
|
|
Shinya Kitaoka |
120a6e |
return QColor::fromHsv(359 * u / 255, v, m_color.v() * 255 / 100).rgba();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class shademaker=""></class>
|
|
Shinya Kitaoka |
120a6e |
QPixmap makeLinearShading(const ShadeMaker &shadeMaker, int size,
|
|
Shinya Kitaoka |
120a6e |
bool isVertical) {
|
|
Shinya Kitaoka |
120a6e |
assert(size > 0);
|
|
Shinya Kitaoka |
120a6e |
QPixmap bgPixmap;
|
|
Shinya Kitaoka |
120a6e |
int i, dx, dy, w = 1, h = 1;
|
|
Shinya Kitaoka |
120a6e |
int x = 0, y = 0;
|
|
Shinya Kitaoka |
120a6e |
if (isVertical) {
|
|
Shinya Kitaoka |
120a6e |
dx = 0;
|
|
Shinya Kitaoka |
120a6e |
dy = -1;
|
|
Shinya Kitaoka |
120a6e |
h = size;
|
|
Shinya Kitaoka |
120a6e |
y = size - 1;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
dx = 1;
|
|
Shinya Kitaoka |
120a6e |
dy = 0;
|
|
Shinya Kitaoka |
120a6e |
w = size;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
QImage image(w, h, QImage::Format_ARGB32);
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < size; i++) {
|
|
Shinya Kitaoka |
120a6e |
int v = 255 * i / (size - 1);
|
|
Shinya Kitaoka |
120a6e |
image.setPixel(x, y, shadeMaker.shade(v));
|
|
Shinya Kitaoka |
120a6e |
x += dx;
|
|
Shinya Kitaoka |
120a6e |
y += dy;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return QPixmap::fromImage(image);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPixmap makeLinearShading(const ColorModel &color, ColorChannel channel,
|
|
Shinya Kitaoka |
120a6e |
int size, bool isVertical) {
|
|
Shinya Kitaoka |
120a6e |
switch (channel) {
|
|
Shinya Kitaoka |
120a6e |
case eRed:
|
|
Shinya Kitaoka |
120a6e |
if (isVertical)
|
|
Shinya Kitaoka |
120a6e |
return makeLinearShading(RedShadeMaker(color), size, isVertical);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return QPixmap(":Resources/grad_r.png").scaled(size, 1);
|
|
Shinya Kitaoka |
120a6e |
case eGreen:
|
|
Shinya Kitaoka |
120a6e |
if (isVertical)
|
|
Shinya Kitaoka |
120a6e |
return makeLinearShading(GreenShadeMaker(color), size, isVertical);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return QPixmap(":Resources/grad_g.png").scaled(size, 1);
|
|
Shinya Kitaoka |
120a6e |
case eBlue:
|
|
Shinya Kitaoka |
120a6e |
if (isVertical)
|
|
Shinya Kitaoka |
120a6e |
return makeLinearShading(BlueShadeMaker(color), size, isVertical);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return QPixmap(":Resources/grad_b.png").scaled(size, 1);
|
|
Shinya Kitaoka |
120a6e |
case eAlpha:
|
|
Shinya Kitaoka |
120a6e |
if (isVertical)
|
|
Shinya Kitaoka |
120a6e |
return makeLinearShading(AlphaShadeMaker(color), size, isVertical);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return QPixmap(":Resources/grad_m.png").scaled(size, 1);
|
|
Shinya Kitaoka |
120a6e |
case eHue:
|
|
Shinya Kitaoka |
120a6e |
return makeLinearShading(HueShadeMaker(color), size, isVertical);
|
|
Shinya Kitaoka |
120a6e |
case eSaturation:
|
|
Shinya Kitaoka |
120a6e |
return makeLinearShading(SaturationShadeMaker(color), size, isVertical);
|
|
Shinya Kitaoka |
120a6e |
case eValue:
|
|
Shinya Kitaoka |
120a6e |
return makeLinearShading(ValueShadeMaker(color), size, isVertical);
|
|
Shinya Kitaoka |
120a6e |
default:
|
|
Shinya Kitaoka |
120a6e |
assert(0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return QPixmap();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class shademaker=""></class>
|
|
Shinya Kitaoka |
120a6e |
QPixmap makeSquareShading(const ShadeMaker &shadeMaker, int size) {
|
|
Shinya Kitaoka |
120a6e |
assert(size > 0);
|
|
Shinya Kitaoka |
120a6e |
QPixmap bgPixmap;
|
|
Shinya Kitaoka |
120a6e |
QImage image(size, size, QImage::Format_RGB32);
|
|
Shinya Kitaoka |
120a6e |
int i, j;
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < size; j++) {
|
|
Shinya Kitaoka |
120a6e |
int u = 255 - (255 * j / (size - 1));
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < size; i++) {
|
|
Shinya Kitaoka |
120a6e |
int v = 255 * i / (size - 1);
|
|
Shinya Kitaoka |
120a6e |
image.setPixel(i, j, shadeMaker.shade(v, u));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return QPixmap::fromImage(image);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPixmap makeSquareShading(const ColorModel &color, ColorChannel channel,
|
|
Shinya Kitaoka |
120a6e |
int size) {
|
|
Shinya Kitaoka |
120a6e |
switch (channel) {
|
|
Shinya Kitaoka |
120a6e |
case eRed:
|
|
Shinya Kitaoka |
120a6e |
return makeSquareShading(GreenBlueShadeMaker(color), size);
|
|
Shinya Kitaoka |
120a6e |
case eGreen:
|
|
Shinya Kitaoka |
120a6e |
return makeSquareShading(RedBlueShadeMaker(color), size);
|
|
Shinya Kitaoka |
120a6e |
case eBlue:
|
|
Shinya Kitaoka |
120a6e |
return makeSquareShading(RedGreenShadeMaker(color), size);
|
|
Shinya Kitaoka |
120a6e |
case eHue:
|
|
Shinya Kitaoka |
120a6e |
return makeSquareShading(SaturationValueShadeMaker(color), size);
|
|
Shinya Kitaoka |
120a6e |
case eSaturation:
|
|
Shinya Kitaoka |
120a6e |
return makeSquareShading(HueValueShadeMaker(color), size);
|
|
Shinya Kitaoka |
120a6e |
case eValue:
|
|
Shinya Kitaoka |
120a6e |
return makeSquareShading(HueSaturationShadeMaker(color), size);
|
|
Shinya Kitaoka |
120a6e |
default:
|
|
Shinya Kitaoka |
120a6e |
assert(0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return QPixmap();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// HexagonalColorWheel implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
HexagonalColorWheel::HexagonalColorWheel(QWidget *parent)
|
|
shun_iwasawa |
7c988d |
: GLWidgetForHighDpi(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_bgColor(128, 128, 128) // defaul value in case this value does not set
|
|
Shinya Kitaoka |
120a6e |
// in the style sheet
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
setObjectName("HexagonalColorWheel");
|
|
Shinya Kitaoka |
120a6e |
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
Shinya Kitaoka |
120a6e |
setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
m_currentWheel = none;
|
|
shun-iwasawa |
388550 |
if (Preferences::instance()->isColorCalibrationEnabled())
|
|
shun-iwasawa |
388550 |
m_lutCalibrator = new LutCalibrator();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
HexagonalColorWheel::~HexagonalColorWheel() {
|
|
shun-iwasawa |
ad7711 |
if (m_fbo) delete m_fbo;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::initializeGL() {
|
|
shun_iwasawa |
5e0d4f |
initializeOpenGLFunctions();
|
|
shun-iwasawa |
ad7711 |
|
|
shun-iwasawa |
ad7711 |
// to be computed once through the software
|
|
shun-iwasawa |
e40777 |
if (m_lutCalibrator && !m_lutCalibrator->isInitialized()) {
|
|
shun-iwasawa |
388550 |
m_lutCalibrator->initialize();
|
|
shun-iwasawa |
388550 |
connect(context(), SIGNAL(aboutToBeDestroyed()), this,
|
|
shun-iwasawa |
388550 |
SLOT(onContextAboutToBeDestroyed()));
|
|
shun-iwasawa |
388550 |
}
|
|
shun-iwasawa |
ad7711 |
|
|
Shinya Kitaoka |
120a6e |
QColor const color = getBGColor();
|
|
Shinya Kitaoka |
120a6e |
glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
|
|
shun-iwasawa |
e40777 |
|
|
shun-iwasawa |
e40777 |
// Without the following lines, the wheel in a floating style editor
|
|
shun-iwasawa |
e40777 |
// dissapears on switching the room due to context switching.
|
|
shun-iwasawa |
e40777 |
if (m_firstInitialized)
|
|
shun-iwasawa |
e40777 |
m_firstInitialized = false;
|
|
shun-iwasawa |
e40777 |
else {
|
|
shun-iwasawa |
e40777 |
resizeGL(width(), height());
|
|
shun-iwasawa |
e40777 |
update();
|
|
shun-iwasawa |
e40777 |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
7c988d |
void HexagonalColorWheel::resizeGL(int w, int h) {
|
|
shun_iwasawa |
1c961d |
w *= getDevPixRatio();
|
|
shun_iwasawa |
1c961d |
h *= getDevPixRatio();
|
|
shun_iwasawa |
7c988d |
float d = (w - 5.0f) / 2.5f;
|
|
shun_iwasawa |
7c988d |
bool isHorizontallyLong = ((d * 1.732f) < h) ? false : true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (isHorizontallyLong) {
|
|
shun_iwasawa |
7c988d |
m_triEdgeLen = (float)h / 1.732f;
|
|
shun_iwasawa |
7c988d |
m_triHeight = (float)h / 2.0f;
|
|
shun_iwasawa |
7c988d |
m_wheelPosition.setX(((float)w - (m_triEdgeLen * 2.5f + 5.0f)) / 2.0f);
|
|
Shinya Kitaoka |
120a6e |
m_wheelPosition.setY(0.0f);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_triEdgeLen = d;
|
|
Shinya Kitaoka |
120a6e |
m_triHeight = m_triEdgeLen * 0.866f;
|
|
Shinya Kitaoka |
120a6e |
m_wheelPosition.setX(0.0f);
|
|
shun_iwasawa |
7c988d |
m_wheelPosition.setY(((float)h - (m_triHeight * 2.0f)) / 2.0f);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// set all vertices positions
|
|
Shinya Kitaoka |
120a6e |
m_wp[0].setX(m_triEdgeLen);
|
|
Shinya Kitaoka |
120a6e |
m_wp[0].setY(m_triHeight);
|
|
Shinya Kitaoka |
120a6e |
m_wp[1].setX(m_triEdgeLen * 0.5f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[1].setY(0.0f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[2].setX(0.0f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[2].setY(m_triHeight);
|
|
Shinya Kitaoka |
120a6e |
m_wp[3].setX(m_triEdgeLen * 0.5f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[3].setY(m_triHeight * 2.0f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[4].setX(m_triEdgeLen * 1.5f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[4].setY(m_triHeight * 2.0f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[5].setX(m_triEdgeLen * 2.0f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[5].setY(m_triHeight);
|
|
Shinya Kitaoka |
120a6e |
m_wp[6].setX(m_triEdgeLen * 1.5f);
|
|
Shinya Kitaoka |
120a6e |
m_wp[6].setY(0.0f);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_leftp[0].setX(m_wp[6].x() + 5.0f);
|
|
Shinya Kitaoka |
120a6e |
m_leftp[0].setY(0.0f);
|
|
Shinya Kitaoka |
120a6e |
m_leftp[1].setX(m_leftp[0].x() + m_triEdgeLen);
|
|
Shinya Kitaoka |
120a6e |
m_leftp[1].setY(m_triHeight * 2.0f);
|
|
Shinya Kitaoka |
120a6e |
m_leftp[2].setX(m_leftp[1].x());
|
|
Shinya Kitaoka |
120a6e |
m_leftp[2].setY(0.0f);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// GL settings
|
|
shun_iwasawa |
7c988d |
glViewport(0, 0, w, h);
|
|
Shinya Kitaoka |
120a6e |
glMatrixMode(GL_PROJECTION);
|
|
Shinya Kitaoka |
120a6e |
glLoadIdentity();
|
|
shun_iwasawa |
7c988d |
glOrtho(0.0, (GLdouble)w, (GLdouble)h, 0.0, 1.0, -1.0);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
ad7711 |
// remake fbo with new size
|
|
shun-iwasawa |
388550 |
if (m_lutCalibrator && m_lutCalibrator->isValid()) {
|
|
shun-iwasawa |
ad7711 |
if (m_fbo) delete m_fbo;
|
|
shun-iwasawa |
ad7711 |
m_fbo = new QOpenGLFramebufferObject(w, h);
|
|
shun-iwasawa |
ad7711 |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::paintGL() {
|
|
Shinya Kitaoka |
120a6e |
// call ClearColor() here in order to update bg color when the stylesheet is
|
|
Shinya Kitaoka |
120a6e |
// switched
|
|
Shinya Kitaoka |
120a6e |
QColor const color = getBGColor();
|
|
Shinya Kitaoka |
120a6e |
glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
glMatrixMode(GL_MODELVIEW);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
388550 |
if (m_lutCalibrator && m_lutCalibrator->isValid()) m_fbo->bind();
|
|
Keisuke Ogaki |
0c8292 |
|
|
Shinya Kitaoka |
120a6e |
glClear(GL_COLOR_BUFFER_BIT);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
float v = (float)m_color.getValue(eValue) / 100.0f;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
glPushMatrix();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// draw hexagonal color wheel
|
|
Shinya Kitaoka |
120a6e |
glTranslatef(m_wheelPosition.rx(), m_wheelPosition.ry(), 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glBegin(GL_TRIANGLE_FAN);
|
|
Shinya Kitaoka |
120a6e |
glColor3f(v, v, v);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[0].x(), m_wp[0].y());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
glColor3f(0.0f, v, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[1].x(), m_wp[1].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(0.0f, v, v);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[2].x(), m_wp[2].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(0.0f, 0.0f, v);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[3].x(), m_wp[3].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(v, 0.0f, v);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[4].x(), m_wp[4].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(v, 0.0f, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[5].x(), m_wp[5].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(v, v, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[6].x(), m_wp[6].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(0.0f, v, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_wp[1].x(), m_wp[1].y());
|
|
Shinya Kitaoka |
120a6e |
glEnd();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QColor leftCol = QColor().fromHsv(m_color.getValue(eHue), 255, 255);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// draw triangle color picker
|
|
Shinya Kitaoka |
120a6e |
glBegin(GL_TRIANGLES);
|
|
Shinya Kitaoka |
120a6e |
glColor3f(leftCol.redF(), leftCol.greenF(), leftCol.blueF());
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_leftp[0].x(), m_leftp[0].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(0.0f, 0.0f, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_leftp[1].x(), m_leftp[1].y());
|
|
Shinya Kitaoka |
120a6e |
glColor3f(1.0f, 1.0f, 1.0f);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(m_leftp[2].x(), m_leftp[2].y());
|
|
Shinya Kitaoka |
120a6e |
glEnd();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// draw small quad at current color position
|
|
Shinya Kitaoka |
120a6e |
drawCurrentColorMark();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
glPopMatrix();
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
388550 |
if (m_lutCalibrator && m_lutCalibrator->isValid())
|
|
shun-iwasawa |
388550 |
m_lutCalibrator->onEndDraw(m_fbo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::drawCurrentColorMark() {
|
|
Shinya Kitaoka |
120a6e |
int h;
|
|
Shinya Kitaoka |
120a6e |
float s, v;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// show hue in a counterclockwise fashion
|
|
Shinya Kitaoka |
120a6e |
h = 360 - m_color.getValue(eHue);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
s = (float)m_color.getValue(eSaturation) / 100.0f;
|
|
Shinya Kitaoka |
120a6e |
v = (float)m_color.getValue(eValue) / 100.0f;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// d is a distance from a center of the wheel
|
|
Shinya Kitaoka |
120a6e |
float d, phi;
|
|
Shinya Kitaoka |
120a6e |
phi = (float)(h % 60 - 30) / 180.0f * 3.1415f;
|
|
Shinya Kitaoka |
120a6e |
d = s * m_triHeight / cosf(phi);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// set marker color
|
|
Shinya Kitaoka |
120a6e |
if (v > 0.4f)
|
|
Shinya Kitaoka |
120a6e |
glColor3f(0.0f, 0.0f, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
glColor3f(1.0f, 1.0f, 1.0f);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// draw marker (in the wheel)
|
|
Shinya Kitaoka |
120a6e |
glPushMatrix();
|
|
Shinya Kitaoka |
120a6e |
glTranslatef(m_wp[0].x(), m_wp[0].y(), 0.1f);
|
|
Shinya Kitaoka |
120a6e |
glRotatef(h, 0.0, 0.0, 1.0);
|
|
Shinya Kitaoka |
120a6e |
glTranslatef(d, 0.0f, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glRotatef(-h, 0.0, 0.0, 1.0);
|
|
Shinya Kitaoka |
120a6e |
glBegin(GL_LINE_LOOP);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(-3, -3);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(3, -3);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(3, 3);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(-3, 3);
|
|
Shinya Kitaoka |
120a6e |
glEnd();
|
|
Shinya Kitaoka |
120a6e |
glPopMatrix();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// draw marker (in the triangle)
|
|
Shinya Kitaoka |
120a6e |
glPushMatrix();
|
|
Shinya Kitaoka |
120a6e |
glTranslatef(m_leftp[1].x(), m_leftp[1].y(), 0.1f);
|
|
Shinya Kitaoka |
120a6e |
glTranslatef(-m_triEdgeLen * v * s, -m_triHeight * v * 2.0f, 0.0f);
|
|
Shinya Kitaoka |
120a6e |
glBegin(GL_LINE_LOOP);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(-3, -3);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(3, -3);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(3, 3);
|
|
Shinya Kitaoka |
120a6e |
glVertex2f(-3, 3);
|
|
Shinya Kitaoka |
120a6e |
glEnd();
|
|
Shinya Kitaoka |
120a6e |
glPopMatrix();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::mousePressEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (~event->buttons() & Qt::LeftButton) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// check whether the mouse cursor is in the wheel or in the triangle (or
|
|
Shinya Kitaoka |
120a6e |
// nothing).
|
|
shun_iwasawa |
7c988d |
QPoint curPos = event->pos() * getDevPixRatio();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPolygonF wheelPolygon;
|
|
Shinya Kitaoka |
120a6e |
// in the case of the wheel
|
|
Shinya Kitaoka |
120a6e |
wheelPolygon << m_wp[1] << m_wp[2] << m_wp[3] << m_wp[4] << m_wp[5]
|
|
Shinya Kitaoka |
120a6e |
<< m_wp[6];
|
|
Shinya Kitaoka |
120a6e |
wheelPolygon.translate(m_wheelPosition);
|
|
shun_iwasawa |
7c988d |
if (wheelPolygon.toPolygon().containsPoint(curPos, Qt::OddEvenFill)) {
|
|
Shinya Kitaoka |
120a6e |
m_currentWheel = leftWheel;
|
|
shun_iwasawa |
7c988d |
clickLeftWheel(curPos);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
wheelPolygon.clear();
|
|
Shinya Kitaoka |
120a6e |
// in the case of the triangle
|
|
Shinya Kitaoka |
120a6e |
wheelPolygon << m_leftp[0] << m_leftp[1] << m_leftp[2];
|
|
Shinya Kitaoka |
120a6e |
wheelPolygon.translate(m_wheelPosition);
|
|
shun_iwasawa |
7c988d |
if (wheelPolygon.toPolygon().containsPoint(curPos, Qt::OddEvenFill)) {
|
|
Shinya Kitaoka |
120a6e |
m_currentWheel = rightTriangle;
|
|
shun_iwasawa |
7c988d |
clickRightTriangle(curPos);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//... or, in the case of nothing
|
|
Shinya Kitaoka |
120a6e |
m_currentWheel = none;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::mouseMoveEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
// change the behavior according to the current touching wheel
|
|
Shinya Kitaoka |
120a6e |
switch (m_currentWheel) {
|
|
Shinya Kitaoka |
120a6e |
case none:
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case leftWheel:
|
|
shun_iwasawa |
7c988d |
clickLeftWheel(event->pos() * getDevPixRatio());
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case rightTriangle:
|
|
shun_iwasawa |
7c988d |
clickRightTriangle(event->pos() * getDevPixRatio());
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::mouseReleaseEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
m_currentWheel = none;
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! compute hue and saturation position. saturation value must be clamped
|
|
shun-iwasawa |
e40777 |
*/
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::clickLeftWheel(const QPoint &pos) {
|
|
Shinya Kitaoka |
120a6e |
QLineF p(m_wp[0] + m_wheelPosition, QPointF(pos));
|
|
Shinya Kitaoka |
120a6e |
QLineF horizontal(0, 0, 1, 0);
|
|
Shinya Kitaoka |
120a6e |
float theta = (p.dy() < 0) ? p.angle(horizontal) : 360 - p.angle(horizontal);
|
|
Shinya Kitaoka |
120a6e |
float phi = theta;
|
|
Shinya Kitaoka |
120a6e |
while (phi >= 60.0f) phi -= 60.0f;
|
|
Shinya Kitaoka |
120a6e |
phi -= 30.0f;
|
|
Shinya Kitaoka |
120a6e |
// d is a length from center to edge of the wheel when saturation = 100
|
|
Shinya Kitaoka |
120a6e |
float d = m_triHeight / cosf(phi / 180.0f * 3.1415f);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
e40777 |
int h = (int)theta;
|
|
Shinya Kitaoka |
120a6e |
if (h > 359) h = 359;
|
|
Shinya Kitaoka |
120a6e |
// clamping
|
|
Shinya Kitaoka |
120a6e |
int s = (int)(std::min(p.length() / d, 1.0) * 100.0f);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_color.setValues(eValue, h, s);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::clickRightTriangle(const QPoint &pos) {
|
|
Shinya Kitaoka |
120a6e |
int s, v;
|
|
Shinya Kitaoka |
120a6e |
QPointF p = m_leftp[1] + m_wheelPosition - QPointF(pos);
|
|
Shinya Kitaoka |
120a6e |
if (p.ry() <= 0.0f) {
|
|
Shinya Kitaoka |
120a6e |
s = 0;
|
|
Shinya Kitaoka |
120a6e |
v = 0;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
float v_ratio = std::min((float)(p.ry() / (m_triHeight * 2.0f)), 1.0f);
|
|
Shinya Kitaoka |
120a6e |
float s_f = p.rx() / (m_triEdgeLen * v_ratio);
|
|
Shinya Kitaoka |
120a6e |
v = (int)(v_ratio * 100.0f);
|
|
Shinya Kitaoka |
120a6e |
s = (int)(std::min(std::max(s_f, 0.0f), 1.0f) * 100.0f);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_color.setValues(eHue, s, v);
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
388550 |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
388550 |
|
|
shun-iwasawa |
388550 |
void HexagonalColorWheel::onContextAboutToBeDestroyed() {
|
|
shun-iwasawa |
388550 |
if (!m_lutCalibrator) return;
|
|
shun-iwasawa |
388550 |
makeCurrent();
|
|
shun-iwasawa |
388550 |
m_lutCalibrator->cleanup();
|
|
shun-iwasawa |
388550 |
doneCurrent();
|
|
shun-iwasawa |
388550 |
}
|
|
shun-iwasawa |
388550 |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// SquaredColorWheel implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
SquaredColorWheel::SquaredColorWheel(QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: QWidget(parent), m_channel(eRed), m_color() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SquaredColorWheel::paintEvent(QPaintEvent *) {
|
|
Shinya Kitaoka |
120a6e |
QPainter p(this);
|
|
Shinya Kitaoka |
120a6e |
// calcolo lo sfondo
|
|
Shinya Kitaoka |
120a6e |
int size = width();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QPixmap bgPixmap = makeSquareShading(m_color, m_channel, size);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!bgPixmap.isNull()) p.drawTiledPixmap(0, 0, size, size, bgPixmap);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int u = 0, v = 0;
|
|
Shinya Kitaoka |
120a6e |
m_color.getValues(m_channel, u, v);
|
|
Shinya Kitaoka |
120a6e |
int x = u * width() / ChannelPairMaxValues[m_channel][0];
|
|
Shinya Kitaoka |
120a6e |
int y = (ChannelPairMaxValues[m_channel][1] - v) * height() /
|
|
Shinya Kitaoka |
120a6e |
ChannelPairMaxValues[m_channel][1];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_color.v() > 127)
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::black);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::white);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(x - 1, y - 1, 3, 3);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SquaredColorWheel::click(const QPoint &pos) {
|
|
Shinya Kitaoka |
120a6e |
int u = ChannelPairMaxValues[m_channel][0] * pos.x() / width();
|
|
Shinya Kitaoka |
120a6e |
int v = ChannelPairMaxValues[m_channel][1] * (height() - pos.y()) / height();
|
|
Shinya Kitaoka |
120a6e |
u = tcrop(u, 0, ChannelPairMaxValues[m_channel][0]);
|
|
Shinya Kitaoka |
120a6e |
v = tcrop(v, 0, ChannelPairMaxValues[m_channel][1]);
|
|
Shinya Kitaoka |
120a6e |
m_color.setValues(m_channel, u, v);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SquaredColorWheel::mousePressEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (event->buttons() & Qt::LeftButton) click(event->pos());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SquaredColorWheel::mouseMoveEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (event->buttons() & Qt::LeftButton) click(event->pos());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SquaredColorWheel::mouseReleaseEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SquaredColorWheel::setColor(const ColorModel &color) { m_color = color; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SquaredColorWheel::setChannel(int channel) {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= channel && channel < 7);
|
|
Shinya Kitaoka |
120a6e |
m_channel = (ColorChannel)channel;
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ColorSlider implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ColorSlider::ColorSlider(Qt::Orientation orientation, QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: QSlider(orientation, parent), m_channel(eRed), m_color() {
|
|
Shinya Kitaoka |
120a6e |
setFocusPolicy(Qt::NoFocus);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setOrientation(orientation);
|
|
Shinya Kitaoka |
120a6e |
setMinimum(0);
|
|
Shinya Kitaoka |
120a6e |
setMaximum(ChannelMaxValues[m_channel]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setMinimumHeight(7);
|
|
Shinya Kitaoka |
120a6e |
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Attenzione: necessario per poter individuare l'oggetto nel file di
|
|
Shinya Kitaoka |
120a6e |
// definizione dello stile
|
|
Shinya Kitaoka |
120a6e |
setObjectName("colorSlider");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorSlider::setChannel(ColorChannel channel) {
|
|
Shinya Kitaoka |
120a6e |
if (m_channel == channel) return;
|
|
Shinya Kitaoka |
120a6e |
m_channel = channel;
|
|
Shinya Kitaoka |
120a6e |
setMaximum(ChannelMaxValues[m_channel]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorSlider::setColor(const ColorModel &color) { m_color = color; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorSlider::paintEvent(QPaintEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
QPainter p(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int x = rect().x();
|
|
Shinya Kitaoka |
120a6e |
int y = rect().y();
|
|
Shinya Kitaoka |
120a6e |
int w = width();
|
|
Shinya Kitaoka |
120a6e |
int h = height();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool isVertical = orientation() == Qt::Vertical;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!isVertical) h -= 5;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPixmap bgPixmap =
|
|
Shinya Kitaoka |
120a6e |
makeLinearShading(m_color, m_channel, isVertical ? h : w, isVertical);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_channel == eAlpha) {
|
|
Shinya Kitaoka |
120a6e |
static QPixmap checkboard(":Resources/backg.png");
|
|
Shinya Kitaoka |
120a6e |
p.drawTiledPixmap(x, y, w, h, checkboard);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!bgPixmap.isNull()) {
|
|
Shinya Kitaoka |
120a6e |
p.drawTiledPixmap(x, y, w, h, bgPixmap);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::white);
|
|
Shinya Kitaoka |
120a6e |
p.drawLine(x, y + h, x + w, y + h);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
Bug in Qt 4.3: The vertical Slider cannot be styled due to a bug.
|
|
Shinya Kitaoka |
120a6e |
In this case we draw "manually" the slider handle at correct position
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
if (isVertical) {
|
|
Shinya Kitaoka |
120a6e |
int pos = QStyle::sliderPositionFromValue(minimum(), maximum(), value(),
|
|
Shinya Kitaoka |
120a6e |
h - 9, true);
|
|
Shinya Kitaoka |
120a6e |
static QPixmap vHandlePixmap(":Resources/v_chandle.png");
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(0, pos, vHandlePixmap);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
static QPixmap hHandleUpPm(":Resources/h_chandleUp.png");
|
|
Shinya Kitaoka |
120a6e |
static QPixmap hHandleDownPm(":Resources/h_chandleDown.png");
|
|
Shinya Kitaoka |
120a6e |
static QPixmap hHandleCenterPm(":Resources/h_chandleCenter.png");
|
|
Shinya Kitaoka |
120a6e |
int pos = QStyle::sliderPositionFromValue(
|
|
Shinya Kitaoka |
120a6e |
0, maximum(), value(), width() - hHandleCenterPm.width(), false);
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(pos, 0, hHandleUpPm);
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(pos, height() - hHandleDownPm.height(), hHandleDownPm);
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(pos, hHandleUpPm.height(), hHandleCenterPm.width(),
|
|
Shinya Kitaoka |
120a6e |
height() - hHandleUpPm.height() - hHandleDownPm.height(),
|
|
Shinya Kitaoka |
120a6e |
hHandleCenterPm);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorSlider::mousePressEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
// vogliamo che facendo click sullo slider, lontano dall'handle
|
|
Shinya Kitaoka |
120a6e |
// l'handle salti subito nella posizione giusta invece di far partire
|
|
Shinya Kitaoka |
120a6e |
// l'autorepeat.
|
|
Shinya Kitaoka |
120a6e |
//
|
|
Shinya Kitaoka |
120a6e |
// cfr. qslider.cpp:429: sembra che questo comportamento si possa ottenere
|
|
Shinya Kitaoka |
120a6e |
// anche con SH_Slider_AbsoluteSetButtons. Ma non capisco come si possa fare
|
|
Shinya Kitaoka |
120a6e |
// per definire quest hint
|
|
Shinya Kitaoka |
120a6e |
QStyleOptionSlider opt;
|
|
Shinya Kitaoka |
120a6e |
initStyleOption(&opt);
|
|
Shinya Kitaoka |
120a6e |
const QRect handleRect = style()->subControlRect(
|
|
Shinya Kitaoka |
120a6e |
QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
|
|
Shinya Kitaoka |
120a6e |
if (!handleRect.contains(event->pos())) {
|
|
Shinya Kitaoka |
120a6e |
const QPoint handleCenter = handleRect.center();
|
|
Shinya Kitaoka |
120a6e |
const QRect grooveRect = style()->subControlRect(
|
|
Shinya Kitaoka |
120a6e |
QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
|
|
Shinya Kitaoka |
120a6e |
int pos, span;
|
|
Shinya Kitaoka |
120a6e |
bool upsideDown = false;
|
|
Shinya Kitaoka |
120a6e |
if (opt.orientation == Qt::Vertical) {
|
|
Shinya Kitaoka |
120a6e |
upsideDown = true;
|
|
Shinya Kitaoka |
120a6e |
int handleSize = handleRect.height();
|
|
Shinya Kitaoka |
120a6e |
pos = event->pos().y() - handleSize / 2;
|
|
Shinya Kitaoka |
120a6e |
span = grooveRect.height() - handleSize;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
int handleSize = QPixmap(":Resources/h_chandleCenter.png").width();
|
|
Shinya Kitaoka |
120a6e |
pos = event->pos().x() - handleSize / 2;
|
|
Shinya Kitaoka |
120a6e |
span = grooveRect.width() - handleSize;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
int value = QStyle::sliderValueFromPosition(minimum(), maximum(), pos, span,
|
|
Shinya Kitaoka |
120a6e |
upsideDown);
|
|
Shinya Kitaoka |
120a6e |
setValue(value);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
QSlider::mousePressEvent(event);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void ColorSlider::mouseReleaseEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
emit sliderReleased();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ArrowButton implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ArrowButton::ArrowButton(QWidget *parent, Qt::Orientation orientation,
|
|
Shinya Kitaoka |
120a6e |
bool isFirstArrow)
|
|
Shinya Kitaoka |
120a6e |
: QToolButton(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_orientaion(orientation)
|
|
Shinya Kitaoka |
120a6e |
, m_isFirstArrow(isFirstArrow)
|
|
Shinya Kitaoka |
120a6e |
, m_timerId(0)
|
|
Shinya Kitaoka |
120a6e |
, m_firstTimerId(0) {
|
|
Shinya Kitaoka |
120a6e |
setFixedSize(10, 10);
|
|
Shinya Kitaoka |
120a6e |
setObjectName("StyleEditorArrowButton");
|
|
Shinya Kitaoka |
120a6e |
bool isVertical = orientation == Qt::Vertical;
|
|
Shinya Kitaoka |
120a6e |
if (m_isFirstArrow) {
|
|
Shinya Kitaoka |
120a6e |
if (isVertical)
|
|
Shinya Kitaoka |
120a6e |
setIcon(createQIconPNG("arrow_up"));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
setIcon(createQIconPNG("arrow_left"));
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (isVertical)
|
|
Shinya Kitaoka |
120a6e |
setIcon(createQIconPNG("arrow_down"));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
setIcon(createQIconPNG("arrow_right"));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
connect(this, SIGNAL(pressed()), this, SLOT(onPressed()));
|
|
Shinya Kitaoka |
120a6e |
connect(this, SIGNAL(released()), this, SLOT(onRelease()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ArrowButton::timerEvent(QTimerEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (m_firstTimerId != 0) {
|
|
Shinya Kitaoka |
120a6e |
killTimer(m_firstTimerId);
|
|
Shinya Kitaoka |
120a6e |
m_firstTimerId = 0;
|
|
Shinya Kitaoka |
120a6e |
m_timerId = startTimer(10);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
notifyChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ArrowButton::notifyChanged() {
|
|
Shinya Kitaoka |
120a6e |
bool isVertical = m_orientaion == Qt::Vertical;
|
|
Shinya Kitaoka |
120a6e |
if ((m_isFirstArrow && !isVertical) || (!m_isFirstArrow && isVertical))
|
|
Shinya Kitaoka |
120a6e |
emit remove();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
emit add();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ArrowButton::onPressed() {
|
|
Shinya Kitaoka |
120a6e |
notifyChanged();
|
|
Shinya Kitaoka |
120a6e |
assert(m_timerId == 0 && m_firstTimerId == 0);
|
|
Shinya Kitaoka |
120a6e |
m_firstTimerId = startTimer(500);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void ArrowButton::onRelease() {
|
|
Shinya Kitaoka |
120a6e |
if (m_firstTimerId != 0) {
|
|
Shinya Kitaoka |
120a6e |
killTimer(m_firstTimerId);
|
|
Shinya Kitaoka |
120a6e |
m_firstTimerId = 0;
|
|
Shinya Kitaoka |
120a6e |
} else if (m_timerId != 0) {
|
|
Shinya Kitaoka |
120a6e |
killTimer(m_timerId);
|
|
Shinya Kitaoka |
120a6e |
m_timerId = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ColorSliderBar implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ColorSliderBar::ColorSliderBar(QWidget *parent, Qt::Orientation orientation)
|
|
Shinya Kitaoka |
120a6e |
: QWidget(parent) {
|
|
Shinya Kitaoka |
120a6e |
bool isVertical = orientation == Qt::Vertical;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ArrowButton *first = new ArrowButton(this, orientation, true);
|
|
Shinya Kitaoka |
120a6e |
connect(first, SIGNAL(remove()), this, SLOT(onRemove()));
|
|
Shinya Kitaoka |
120a6e |
connect(first, SIGNAL(add()), this, SLOT(onAdd()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_colorSlider = new ColorSlider(orientation, this);
|
|
Shinya Kitaoka |
120a6e |
if (isVertical) m_colorSlider->setMaximumWidth(22);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ArrowButton *last = new ArrowButton(this, orientation, false);
|
|
Shinya Kitaoka |
120a6e |
connect(last, SIGNAL(add()), this, SLOT(onAdd()));
|
|
Shinya Kitaoka |
120a6e |
connect(last, SIGNAL(remove()), this, SLOT(onRemove()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
connect(m_colorSlider, SIGNAL(valueChanged(int)), this,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(valueChanged(int)));
|
|
Shinya Kitaoka |
120a6e |
connect(m_colorSlider, SIGNAL(sliderReleased()), this,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(valueChanged()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QBoxLayout *layout;
|
|
Shinya Kitaoka |
120a6e |
if (!isVertical)
|
|
Shinya Kitaoka |
120a6e |
layout = new QHBoxLayout(this);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
layout = new QVBoxLayout(this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
layout->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
layout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
layout->addWidget(first, 0, Qt::AlignCenter);
|
|
Shinya Kitaoka |
120a6e |
layout->addWidget(m_colorSlider, 1);
|
|
Shinya Kitaoka |
120a6e |
layout->addWidget(last, 0, Qt::AlignCenter);
|
|
Shinya Kitaoka |
120a6e |
setLayout(layout);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorSliderBar::onRemove() {
|
|
Shinya Kitaoka |
120a6e |
int value = m_colorSlider->value();
|
|
Shinya Kitaoka |
120a6e |
if (value <= m_colorSlider->minimum()) return;
|
|
Shinya Kitaoka |
120a6e |
m_colorSlider->setValue(value - 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorSliderBar::onAdd() {
|
|
Shinya Kitaoka |
120a6e |
int value = m_colorSlider->value();
|
|
Shinya Kitaoka |
120a6e |
if (value >= m_colorSlider->maximum()) return;
|
|
Shinya Kitaoka |
120a6e |
m_colorSlider->setValue(value + 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ChannelLineEdit implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ChannelLineEdit::mousePressEvent(QMouseEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
IntLineEdit::mousePressEvent(e);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_isEditing) {
|
|
Shinya Kitaoka |
120a6e |
selectAll();
|
|
Shinya Kitaoka |
120a6e |
m_isEditing = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ChannelLineEdit::focusOutEvent(QFocusEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
IntLineEdit::focusOutEvent(e);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_isEditing = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ChannelLineEdit::paintEvent(QPaintEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
IntLineEdit::paintEvent(e);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_isEditing) {
|
|
Shinya Kitaoka |
120a6e |
QPainter p(this);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::yellow);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(rect().adjusted(0, 0, -1, -1));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ColorChannelControl implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ColorChannelControl::ColorChannelControl(ColorChannel channel, QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: QWidget(parent), m_channel(channel), m_value(0), m_signalEnabled(true) {
|
|
Shinya Kitaoka |
120a6e |
setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
7ae920 |
QStringList channelList;
|
|
Jeremy Bullock |
7ae920 |
channelList << tr("R") << tr("G") << tr("B") << tr("A") << tr("H") << tr("S")
|
|
Jeremy Bullock |
7ae920 |
<< tr("V");
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= (int)m_channel && (int)m_channel < 7);
|
|
Jeremy Bullock |
7ae920 |
QString text = channelList.at(m_channel);
|
|
Shinya Kitaoka |
120a6e |
m_label = new QLabel(text, this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int minValue = 0;
|
|
Shinya Kitaoka |
120a6e |
int maxValue = 0;
|
|
Shinya Kitaoka |
120a6e |
if (m_channel < 4) // RGBA
|
|
Shinya Kitaoka |
120a6e |
maxValue = 255;
|
|
Shinya Kitaoka |
120a6e |
else if (m_channel == 4) // H
|
|
Shinya Kitaoka |
120a6e |
maxValue = 359;
|
|
Shinya Kitaoka |
120a6e |
else // SV
|
|
Shinya Kitaoka |
120a6e |
maxValue = 100;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_field = new ChannelLineEdit(this, 0, minValue, maxValue);
|
|
Shinya Kitaoka |
120a6e |
m_slider = new ColorSlider(Qt::Horizontal, this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// buttons to increment/decrement the values by 1
|
|
Shinya Kitaoka |
120a6e |
QPushButton *addButton = new QPushButton(this);
|
|
Shinya Kitaoka |
120a6e |
QPushButton *subButton = new QPushButton(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_slider->setValue(0);
|
|
Shinya Kitaoka |
120a6e |
m_slider->setChannel(m_channel);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_label->setObjectName("colorSliderLabel");
|
|
Shinya Kitaoka |
120a6e |
m_label->setFixedWidth(11);
|
|
Shinya Kitaoka |
120a6e |
m_label->setMinimumHeight(7);
|
|
Shinya Kitaoka |
120a6e |
m_label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_field->setObjectName("colorSliderField");
|
|
Shinya Kitaoka |
120a6e |
m_field->setFixedWidth(fontMetrics().width('0') * 6 + 5);
|
|
Shinya Kitaoka |
120a6e |
m_field->setMinimumHeight(7);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
addButton->setObjectName("colorSliderAddButton");
|
|
Shinya Kitaoka |
120a6e |
subButton->setObjectName("colorSliderSubButton");
|
|
Shinya Kitaoka |
120a6e |
addButton->setFixedWidth(18);
|
|
Shinya Kitaoka |
120a6e |
subButton->setFixedWidth(18);
|
|
Shinya Kitaoka |
120a6e |
addButton->setMinimumHeight(7);
|
|
Shinya Kitaoka |
120a6e |
subButton->setMinimumHeight(7);
|
|
Shinya Kitaoka |
120a6e |
addButton->setFlat(true);
|
|
Shinya Kitaoka |
120a6e |
subButton->setFlat(true);
|
|
Shinya Kitaoka |
120a6e |
addButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
Shinya Kitaoka |
120a6e |
subButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
Shinya Kitaoka |
120a6e |
addButton->setAutoRepeat(true);
|
|
Shinya Kitaoka |
120a6e |
subButton->setAutoRepeat(true);
|
|
Shinya Kitaoka |
120a6e |
addButton->setAutoRepeatInterval(25);
|
|
Shinya Kitaoka |
120a6e |
subButton->setAutoRepeatInterval(25);
|
|
Shinya Kitaoka |
120a6e |
addButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
subButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *mainLayout = new QHBoxLayout(this);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setSpacing(1);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(m_label, 0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addSpacing(2);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(m_field, 0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addSpacing(2);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(subButton, 0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(m_slider, 1);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(addButton, 0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
setLayout(mainLayout);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool ret =
|
|
Shinya Kitaoka |
120a6e |
connect(m_field, SIGNAL(editingFinished()), this, SLOT(onFieldChanged()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_slider, SIGNAL(valueChanged(int)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onSliderChanged(int)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_slider, SIGNAL(sliderReleased()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onSliderReleased()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret &&
|
|
Shinya Kitaoka |
120a6e |
connect(addButton, SIGNAL(clicked()), this, SLOT(onAddButtonClicked()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret &&
|
|
Shinya Kitaoka |
120a6e |
connect(subButton, SIGNAL(clicked()), this, SLOT(onSubButtonClicked()));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorChannelControl::onAddButtonClicked() {
|
|
Shinya Kitaoka |
120a6e |
m_slider->setValue(m_slider->value() + 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorChannelControl::onSubButtonClicked() {
|
|
Shinya Kitaoka |
120a6e |
m_slider->setValue(m_slider->value() - 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorChannelControl::setColor(const ColorModel &color) {
|
|
Shinya Kitaoka |
120a6e |
m_color = color;
|
|
Shinya Kitaoka |
120a6e |
m_slider->setColor(color);
|
|
Shinya Kitaoka |
120a6e |
int value = color.getValue(m_channel);
|
|
Shinya Kitaoka |
120a6e |
if (m_value != value) {
|
|
Shinya Kitaoka |
120a6e |
bool signalEnabled = m_signalEnabled;
|
|
Shinya Kitaoka |
120a6e |
m_signalEnabled = false;
|
|
Shinya Kitaoka |
120a6e |
m_value = value;
|
|
Shinya Kitaoka |
120a6e |
m_field->setText(QString::number(value));
|
|
Shinya Kitaoka |
120a6e |
m_slider->setValue(value);
|
|
Shinya Kitaoka |
120a6e |
m_signalEnabled = signalEnabled;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorChannelControl::onFieldChanged() {
|
|
Shinya Kitaoka |
120a6e |
int value = m_field->text().toInt();
|
|
Shinya Kitaoka |
120a6e |
if (m_value == value) return;
|
|
Shinya Kitaoka |
120a6e |
m_value = value;
|
|
Shinya Kitaoka |
120a6e |
m_slider->setValue(value);
|
|
Shinya Kitaoka |
120a6e |
if (m_signalEnabled) {
|
|
Shinya Kitaoka |
120a6e |
m_color.setValue(m_channel, value);
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorChannelControl::onSliderChanged(int value) {
|
|
Shinya Kitaoka |
120a6e |
if (m_value == value) return;
|
|
Shinya Kitaoka |
120a6e |
m_value = value;
|
|
Shinya Kitaoka |
120a6e |
m_field->setText(QString::number(value));
|
|
Shinya Kitaoka |
120a6e |
if (m_signalEnabled) {
|
|
Shinya Kitaoka |
120a6e |
m_color.setValue(m_channel, value);
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void ColorChannelControl::onSliderReleased() {
|
|
Shinya Kitaoka |
120a6e |
emit colorChanged(m_color, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// StyleEditorPage implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
StyleEditorPage::StyleEditorPage(QWidget *parent) : QFrame(parent) {
|
|
Shinya Kitaoka |
120a6e |
setFocusPolicy(Qt::NoFocus);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// It is necessary for the style sheets
|
|
Shinya Kitaoka |
120a6e |
setObjectName("styleEditorPage");
|
|
Shinya Kitaoka |
120a6e |
setFrameStyle(QFrame::StyledPanel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ColorParameterSelector implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ColorParameterSelector::ColorParameterSelector(QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: QWidget(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_index(-1)
|
|
Shinya Kitaoka |
120a6e |
, m_chipSize(21, 21)
|
|
Shinya Kitaoka |
120a6e |
, m_chipOrigin(0, 1)
|
|
Shinya Kitaoka |
120a6e |
, m_chipDelta(21, 0) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void ColorParameterSelector::paintEvent(QPaintEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (m_colors.empty()) return;
|
|
Shinya Kitaoka |
120a6e |
QPainter p(this);
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
QRect currentChipRect = QRect();
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)m_colors.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
QRect chipRect(m_chipOrigin + i * m_chipDelta, m_chipSize);
|
|
Shinya Kitaoka |
120a6e |
p.fillRect(chipRect, m_colors[i]);
|
|
Shinya Kitaoka |
120a6e |
if (i == m_index) currentChipRect = chipRect;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// Current index border
|
|
Shinya Kitaoka |
120a6e |
if (!currentChipRect.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
p.setPen(QColor(199, 202, 50));
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(currentChipRect.adjusted(0, 0, -1, -1));
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::white);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(currentChipRect.adjusted(1, 1, -2, -2));
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::black);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(currentChipRect.adjusted(2, 2, -3, -3));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorParameterSelector::setStyle(const TColorStyle &style) {
|
|
Shinya Kitaoka |
120a6e |
int count = style.getColorParamCount();
|
|
Shinya Kitaoka |
120a6e |
if (count <= 1) {
|
|
Shinya Kitaoka |
120a6e |
clear();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (m_colors.size() != count) {
|
|
Shinya Kitaoka |
120a6e |
m_index = 0;
|
|
Shinya Kitaoka |
120a6e |
m_colors.resize(count);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < count; i++) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 color = style.getColorParamValue(i);
|
|
Shinya Kitaoka |
120a6e |
m_colors[i] = QColor(color.r, color.g, color.b, color.m);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ColorParameterSelector::clear() {
|
|
Shinya Kitaoka |
120a6e |
if (m_colors.size() != 0) m_colors.clear();
|
|
Shinya Kitaoka |
120a6e |
m_index = -1;
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void ColorParameterSelector::mousePressEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
QPoint pos = event->pos() - m_chipOrigin;
|
|
Shinya Kitaoka |
120a6e |
int index = pos.x() / m_chipDelta.x();
|
|
Shinya Kitaoka |
120a6e |
QRect chipRect(index * m_chipDelta, m_chipSize);
|
|
Shinya Kitaoka |
120a6e |
if (chipRect.contains(pos)) {
|
|
Shinya Kitaoka |
120a6e |
m_index = index;
|
|
Shinya Kitaoka |
120a6e |
emit colorParamChanged();
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// PlainColorPage implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
PlainColorPage::PlainColorPage(QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: StyleEditorPage(parent), m_color(), m_signalEnabled(true) {
|
|
Shinya Kitaoka |
120a6e |
setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// m_squaredColorWheel = new SquaredColorWheel(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// m_verticalSlider = new ColorSliderBar(this, Qt::Vertical);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_hexagonalColorWheel = new HexagonalColorWheel(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
QButtonGroup *channelButtonGroup = new QButtonGroup();
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i<7; i++)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
if (i != (int)eAlpha)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
QRadioButton *button = new QRadioButton(this);
|
|
Shinya Kitaoka |
120a6e |
m_modeButtons[i] = button;
|
|
Shinya Kitaoka |
120a6e |
if (i == 0) button->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
channelButtonGroup->addButton(button, i);
|
|
Shinya Kitaoka |
120a6e |
//slidersLayout->addWidget(button,i,0);
|
|
Shinya Kitaoka |
120a6e |
//とりあえず隠す
|
|
Shinya Kitaoka |
120a6e |
m_modeButtons[i]->hide();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
m_modeButtons[i] = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_channelControls[i] = new ColorChannelControl((ColorChannel)i, this);
|
|
Shinya Kitaoka |
120a6e |
m_channelControls[i]->setColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
bool ret = connect(m_channelControls[i], SIGNAL(colorChanged(const
|
|
Shinya Kitaoka |
120a6e |
ColorModel &, bool)),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(onControlChanged(const ColorModel &, bool)));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < 7; i++) {
|
|
Shinya Kitaoka |
120a6e |
m_channelControls[i] = new ColorChannelControl((ColorChannel)i, this);
|
|
Shinya Kitaoka |
120a6e |
m_channelControls[i]->setColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
bool ret = connect(m_channelControls[i],
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(colorChanged(const ColorModel &, bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onControlChanged(const ColorModel &, bool)));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
0a2e55 |
m_wheelFrame = new QFrame(this);
|
|
Jeremy Bullock |
0a2e55 |
m_hsvFrame = new QFrame(this);
|
|
Jeremy Bullock |
0a2e55 |
m_alphaFrame = new QFrame(this);
|
|
Jeremy Bullock |
0a2e55 |
m_rgbFrame = new QFrame(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
4bf672 |
m_slidersContainer = new QFrame(this);
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter = new QSplitter(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//プロパティの設定
|
|
Shinya Kitaoka |
120a6e |
// channelButtonGroup->setExclusive(true);
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
m_wheelFrame->setObjectName("PlainColorPageParts");
|
|
Jeremy Bullock |
0a2e55 |
m_hsvFrame->setObjectName("PlainColorPageParts");
|
|
Jeremy Bullock |
0a2e55 |
m_alphaFrame->setObjectName("PlainColorPageParts");
|
|
Jeremy Bullock |
0a2e55 |
m_rgbFrame->setObjectName("PlainColorPageParts");
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->setOrientation(Qt::Vertical);
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// m_verticalSlider->hide();
|
|
Shinya Kitaoka |
120a6e |
// m_squaredColorWheel->hide();
|
|
Shinya Kitaoka |
120a6e |
// m_ghibliColorWheel->hide();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// layout
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *mainLayout = new QVBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *wheelLayout = new QHBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
wheelLayout->setMargin(5);
|
|
Shinya Kitaoka |
120a6e |
wheelLayout->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
{ wheelLayout->addWidget(m_hexagonalColorWheel); }
|
|
Jeremy Bullock |
4bf672 |
m_wheelFrame->setLayout(wheelLayout);
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->addWidget(m_wheelFrame);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *slidersLayout = new QVBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
slidersLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
slidersLayout->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *hsvLayout = new QVBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
hsvLayout->setMargin(4);
|
|
Shinya Kitaoka |
120a6e |
hsvLayout->setSpacing(4);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
hsvLayout->addWidget(m_channelControls[eHue]);
|
|
Shinya Kitaoka |
120a6e |
hsvLayout->addWidget(m_channelControls[eSaturation]);
|
|
Shinya Kitaoka |
120a6e |
hsvLayout->addWidget(m_channelControls[eValue]);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Jeremy Bullock |
0a2e55 |
m_hsvFrame->setLayout(hsvLayout);
|
|
Jeremy Bullock |
0a2e55 |
slidersLayout->addWidget(m_hsvFrame, 3);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
7ae920 |
QVBoxLayout *alphaLayout = new QVBoxLayout();
|
|
Jeremy Bullock |
7ae920 |
alphaLayout->setMargin(4);
|
|
Jeremy Bullock |
7ae920 |
alphaLayout->setSpacing(4);
|
|
Jeremy Bullock |
7ae920 |
{ alphaLayout->addWidget(m_channelControls[eAlpha]); }
|
|
Jeremy Bullock |
0a2e55 |
m_alphaFrame->setLayout(alphaLayout);
|
|
Jeremy Bullock |
0a2e55 |
slidersLayout->addWidget(m_alphaFrame, 1);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *rgbLayout = new QVBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
rgbLayout->setMargin(4);
|
|
Shinya Kitaoka |
120a6e |
rgbLayout->setSpacing(4);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
rgbLayout->addWidget(m_channelControls[eRed]);
|
|
Shinya Kitaoka |
120a6e |
rgbLayout->addWidget(m_channelControls[eGreen]);
|
|
Shinya Kitaoka |
120a6e |
rgbLayout->addWidget(m_channelControls[eBlue]);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Jeremy Bullock |
0a2e55 |
m_rgbFrame->setLayout(rgbLayout);
|
|
Jeremy Bullock |
0a2e55 |
slidersLayout->addWidget(m_rgbFrame, 3);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Jeremy Bullock |
4bf672 |
m_slidersContainer->setLayout(slidersLayout);
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->addWidget(m_slidersContainer);
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
mainLayout->addWidget(m_vSplitter, 1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
setLayout(mainLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QList<int> list;</int>
|
|
Shinya Kitaoka |
120a6e |
list << rect().height() / 2 << rect().height() / 2;
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->setSizes(list);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// connect(m_squaredColorWheel, SIGNAL(colorChanged(const ColorModel &,
|
|
Shinya Kitaoka |
120a6e |
// bool)),
|
|
Shinya Kitaoka |
120a6e |
// this, SLOT(onWheelChanged(const ColorModel &, bool)));
|
|
Shinya Kitaoka |
120a6e |
connect(m_hexagonalColorWheel, SIGNAL(colorChanged(const ColorModel &, bool)),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(onWheelChanged(const ColorModel &, bool)));
|
|
Shinya Kitaoka |
120a6e |
// m_verticalSlider->setMaximumSize(20,150);
|
|
Shinya Kitaoka |
120a6e |
// connect(m_verticalSlider, SIGNAL(valueChanged(int)), this,
|
|
Shinya Kitaoka |
120a6e |
// SLOT(onWheelSliderChanged(int)));
|
|
Shinya Kitaoka |
120a6e |
// connect(m_verticalSlider, SIGNAL(valueChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
// SLOT(onWheelSliderReleased()));
|
|
Shinya Kitaoka |
120a6e |
// connect( m_verticalSlider, SIGNAL(sliderReleased()), this,
|
|
Shinya Kitaoka |
120a6e |
// SLOT(onWheelSliderReleased()));
|
|
Shinya Kitaoka |
120a6e |
// connect(channelButtonGroup, SIGNAL(buttonClicked(int)), this,
|
|
Shinya Kitaoka |
120a6e |
// SLOT(setWheelChannel(int)));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void PlainColorPage::resizeEvent(QResizeEvent *) {
|
|
Shinya Kitaoka |
120a6e |
int w = width();
|
|
Shinya Kitaoka |
120a6e |
int h = height();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int parentW = parentWidget()->width();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void PlainColorPage::updateControls() {
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < 7; i++) {
|
|
Shinya Kitaoka |
120a6e |
m_channelControls[i]->setColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
m_channelControls[i]->update();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
m_squaredColorWheel->setColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
m_squaredColorWheel->update();
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_hexagonalColorWheel->setColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
m_hexagonalColorWheel->update();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
bool signalsBlocked = m_verticalSlider->blockSignals(true);
|
|
Shinya Kitaoka |
120a6e |
m_verticalSlider->setColor(m_color);
|
|
Shinya Kitaoka |
120a6e |
int value = m_color.getValue(m_verticalSlider->getChannel());
|
|
Shinya Kitaoka |
120a6e |
m_verticalSlider->setValue(value);
|
|
Shinya Kitaoka |
120a6e |
m_verticalSlider->update();
|
|
Shinya Kitaoka |
120a6e |
m_verticalSlider->blockSignals(signalsBlocked);
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void PlainColorPage::setColor(const TColorStyle &style,
|
|
Shinya Kitaoka |
120a6e |
int colorParameterIndex) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 newPixel = style.getColorParamValue(colorParameterIndex);
|
|
Shinya Kitaoka |
120a6e |
if (m_color.getTPixel() == newPixel) return;
|
|
Shinya Kitaoka |
120a6e |
bool oldSignalEnabled = m_signalEnabled;
|
|
Shinya Kitaoka |
120a6e |
m_signalEnabled = false;
|
|
Shinya Kitaoka |
120a6e |
m_color.setTPixel(newPixel);
|
|
Shinya Kitaoka |
120a6e |
updateControls();
|
|
Shinya Kitaoka |
120a6e |
m_signalEnabled = oldSignalEnabled;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
void PlainColorPage::setIsVertical(bool isVertical) {
|
|
Jeremy Bullock |
4bf672 |
// if (m_isVertical == isVertical) return;
|
|
Jeremy Bullock |
4bf672 |
// not returning even if it already is the same orientation
|
|
Jeremy Bullock |
4bf672 |
// to take advantage of the resizing here
|
|
Jeremy Bullock |
4bf672 |
// this is useful for the first time the splitter is set
|
|
Jeremy Bullock |
4bf672 |
// afterwards, it will be overridden by the saved state
|
|
Jeremy Bullock |
4bf672 |
// from settings.
|
|
Jeremy Bullock |
4bf672 |
m_isVertical = isVertical;
|
|
Jeremy Bullock |
4bf672 |
if (isVertical) {
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->setOrientation(Qt::Vertical);
|
|
Jeremy Bullock |
4bf672 |
QList<int> sectionSizes;</int>
|
|
Jeremy Bullock |
4bf672 |
// maximize color wheel space
|
|
Jeremy Bullock |
4bf672 |
sectionSizes << height() - 1 << 1;
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->setSizes(sectionSizes);
|
|
Jeremy Bullock |
4bf672 |
} else {
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->setOrientation(Qt::Horizontal);
|
|
Jeremy Bullock |
4bf672 |
QList<int> sectionSizes;</int>
|
|
Jeremy Bullock |
4bf672 |
sectionSizes << width() / 2 << width() / 2;
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->setSizes(sectionSizes);
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
void PlainColorPage::toggleOrientation() { setIsVertical(!m_isVertical); }
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
QByteArray PlainColorPage::getSplitterState() {
|
|
Jeremy Bullock |
4bf672 |
return m_vSplitter->saveState();
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
void PlainColorPage::setSplitterState(QByteArray state) {
|
|
Jeremy Bullock |
4bf672 |
m_vSplitter->restoreState(state);
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void PlainColorPage::setWheelChannel(int channel)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
assert(0<=channel && channel<7);
|
|
Shinya Kitaoka |
120a6e |
m_squaredColorWheel->setChannel(channel);
|
|
Toshihiro Shimizu |
890ddd |
bool signalsBlocked = m_verticalSlider->signalsBlocked();
|
|
Shinya Kitaoka |
120a6e |
m_verticalSlider->blockSignals(true);
|
|
Shinya Kitaoka |
120a6e |
m_verticalSlider->setChannel((ColorChannel)channel);
|
|
Toshihiro Shimizu |
890ddd |
m_verticalSlider->setRange(0,ChannelMaxValues[channel]);
|
|
Toshihiro Shimizu |
890ddd |
m_verticalSlider->setValue(m_color.getValue((ColorChannel)channel));
|
|
Toshihiro Shimizu |
890ddd |
m_verticalSlider->update();
|
|
Toshihiro Shimizu |
890ddd |
m_verticalSlider->blockSignals(signalsBlocked);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void PlainColorPage::onControlChanged(const ColorModel &color,
|
|
Shinya Kitaoka |
120a6e |
bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
if (!(m_color == color)) {
|
|
Shinya Kitaoka |
120a6e |
m_color = color;
|
|
Shinya Kitaoka |
120a6e |
updateControls();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_signalEnabled) emit colorChanged(m_color, isDragging);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void PlainColorPage::onWheelChanged(const ColorModel &color, bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
if (!(m_color == color)) {
|
|
Shinya Kitaoka |
120a6e |
m_color = color;
|
|
Shinya Kitaoka |
120a6e |
updateControls();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (m_signalEnabled) emit colorChanged(m_color, isDragging);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void PlainColorPage::onWheelSliderChanged(int value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
if(m_color.getValue(m_verticalSlider->getChannel()) == value) return;
|
|
Shinya Kitaoka |
120a6e |
m_color.setValue(m_verticalSlider->getChannel(), value);
|
|
Toshihiro Shimizu |
890ddd |
updateControls();
|
|
Toshihiro Shimizu |
890ddd |
if(m_signalEnabled)
|
|
Toshihiro Shimizu |
890ddd |
emit colorChanged(m_color, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void PlainColorPage::onWheelSliderReleased()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
emit colorChanged(m_color, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// StyleChooserPage implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath StyleChooserPage::m_rootPath;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
StyleChooserPage::StyleChooserPage(QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: StyleEditorPage(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_chipOrigin(5, 3)
|
|
Shinya Kitaoka |
120a6e |
, m_chipSize(25, 25)
|
|
Shinya Kitaoka |
120a6e |
, m_chipPerRow(0)
|
|
Shinya Kitaoka |
120a6e |
, m_currentIndex(-1) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void StyleChooserPage::paintEvent(QPaintEvent *) {
|
|
Shinya Kitaoka |
120a6e |
if (loadIfNeeded()) computeSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPainter p(this);
|
|
Shinya Kitaoka |
120a6e |
// p.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
Shinya Kitaoka |
120a6e |
if (m_chipPerRow == 0 || getChipCount() == 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int w = parentWidget()->width();
|
|
Shinya Kitaoka |
120a6e |
int chipLx = m_chipSize.width(), chipLy = m_chipSize.height();
|
|
Shinya Kitaoka |
120a6e |
int nX = m_chipPerRow;
|
|
Shinya Kitaoka |
120a6e |
int nY = (getChipCount() + m_chipPerRow - 1) / m_chipPerRow;
|
|
Shinya Kitaoka |
120a6e |
int x0 = m_chipOrigin.x();
|
|
Shinya Kitaoka |
120a6e |
int y0 = m_chipOrigin.y();
|
|
Shinya Kitaoka |
120a6e |
int i, j;
|
|
Shinya Kitaoka |
120a6e |
QRect currentIndexRect = QRect();
|
|
Shinya Kitaoka |
120a6e |
int count = 0;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < nY; i++)
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < nX; j++) {
|
|
Shinya Kitaoka |
120a6e |
QRect rect(x0 + chipLx * j + 2, y0 + chipLy * i + 2, chipLx, chipLy);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
drawChip(p, rect, count);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::black);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(rect);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_currentIndex == count) currentIndexRect = rect;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
count++;
|
|
Shinya Kitaoka |
120a6e |
if (count >= getChipCount()) break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!currentIndexRect.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
// Draw the curentIndex border
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::white);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(currentIndexRect);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(QColor(199, 202, 50));
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(currentIndexRect.adjusted(1, 1, -1, -1));
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::white);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(currentIndexRect.adjusted(2, 2, -2, -2));
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::black);
|
|
Shinya Kitaoka |
120a6e |
p.drawRect(currentIndexRect.adjusted(3, 3, -3, -3));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleChooserPage::computeSize() {
|
|
Shinya Kitaoka |
120a6e |
int w = width();
|
|
Shinya Kitaoka |
120a6e |
m_chipPerRow = (w - 15) / m_chipSize.width();
|
|
Shinya Kitaoka |
120a6e |
int rowCount = 0;
|
|
Shinya Kitaoka |
120a6e |
if (m_chipPerRow != 0)
|
|
Shinya Kitaoka |
120a6e |
rowCount = (getChipCount() + m_chipPerRow - 1) / m_chipPerRow;
|
|
Jeremy Bullock |
4bf672 |
setMinimumSize(3 * m_chipSize.width(), rowCount * m_chipSize.height() + 10);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int StyleChooserPage::posToIndex(const QPoint &pos) const {
|
|
Shinya Kitaoka |
120a6e |
if (m_chipPerRow == 0) return -1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int x = (pos.x() - m_chipOrigin.x() - 2) / m_chipSize.width();
|
|
Shinya Kitaoka |
120a6e |
if (x >= m_chipPerRow) return -1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int y = (pos.y() - m_chipOrigin.y() - 2) / m_chipSize.height();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int index = x + m_chipPerRow * y;
|
|
Shinya Kitaoka |
120a6e |
if (index < 0 || index >= getChipCount()) return -1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return index;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleChooserPage::mousePressEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
QPoint pos = event->pos();
|
|
Shinya Kitaoka |
120a6e |
int currentIndex = posToIndex(pos);
|
|
Shinya Kitaoka |
120a6e |
if (currentIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
m_currentIndex = currentIndex;
|
|
Shinya Kitaoka |
120a6e |
onSelect(currentIndex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleChooserPage::mouseReleaseEvent(QMouseEvent *event) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
// TOGLIERE
|
|
Shinya Kitaoka |
120a6e |
void StyleChooserPage::setRootPath(const TFilePath &rootPath) {
|
|
Shinya Kitaoka |
120a6e |
m_rootPath = rootPath;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// CustomStyleChooser definition
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class CustomStyleChooserPage final : public StyleChooserPage {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
CustomStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
static CustomStyleManager *styleManager();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
bool event(QEvent *e) override;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void showEvent(QShowEvent *) override {
|
|
Shinya Kitaoka |
120a6e |
connect(styleManager(), SIGNAL(patternAdded()), this, SLOT(computeSize()));
|
|
Shinya Kitaoka |
120a6e |
styleManager()->loadItems();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
void hideEvent(QHideEvent *) override {
|
|
Shinya Kitaoka |
120a6e |
disconnect(styleManager(), SIGNAL(patternAdded()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(computeSize()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
bool loadIfNeeded() override { return false; } // serve?
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(!m_loaded) {loadItems(); m_loaded=true;return true;}
|
|
Shinya Kitaoka |
120a6e |
else return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
int getChipCount() const override {
|
|
Shinya Kitaoka |
38fd86 |
return styleManager()->getPatternCount();
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void drawChip(QPainter &p, QRect rect, int index) override {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= index && index < getChipCount());
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager::PatternData pattern = styleManager()->getPattern(index);
|
|
shun-iwasawa |
c96e49 |
if (pattern.m_image && !pattern.m_image->isNull())
|
|
shun-iwasawa |
c96e49 |
p.drawImage(rect, *pattern.m_image);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
void onSelect(int index) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager *CustomStyleChooserPage::styleManager() {
|
|
Shinya Kitaoka |
120a6e |
static const QString filters(
|
|
Shinya Kitaoka |
120a6e |
"*.pli *.tif *.png *.tga *.tiff *.sgi *.rgb *.pct *.pic");
|
|
Shinya Kitaoka |
120a6e |
static CustomStyleManager theManager(TFilePath("custom styles"), filters);
|
|
Shinya Kitaoka |
120a6e |
return &theManager;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool CustomStyleChooserPage::event(QEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
// Intercept tooltip events
|
|
Shinya Kitaoka |
120a6e |
if (e->type() != QEvent::ToolTip) return StyleChooserPage::event(e);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// see StyleChooserPage::paintEvent
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager *manager = styleManager();
|
|
Shinya Kitaoka |
120a6e |
QHelpEvent *he = static_cast<qhelpevent *="">(e);</qhelpevent>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int chipIdx = posToIndex(he->pos()), chipCount = manager->getPatternCount();
|
|
Shinya Kitaoka |
120a6e |
if (chipIdx < 0 || chipIdx >= chipCount) return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager::PatternData pattern = manager->getPattern(chipIdx);
|
|
Shinya Kitaoka |
120a6e |
QToolTip::showText(he->globalPos(),
|
|
Shinya Kitaoka |
120a6e |
QString::fromStdString(pattern.m_patternName));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void CustomStyleChooserPage::onSelect(int index) {
|
|
Shinya Kitaoka |
120a6e |
if (index < 0 || index >= getChipCount()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager::PatternData pattern = styleManager()->getPattern(index);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_currentIndex < 0) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string name = pattern.m_patternName;
|
|
Shinya Kitaoka |
120a6e |
if (pattern.m_isVector) {
|
|
Shinya Kitaoka |
120a6e |
TVectorImagePatternStrokeStyle cs(name);
|
|
Shinya Kitaoka |
120a6e |
emit styleSelected(cs);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TRasterImagePatternStrokeStyle cs(name);
|
|
Shinya Kitaoka |
120a6e |
emit styleSelected(cs);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// VectorBrushStyleChooser definition
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class VectorBrushStyleChooserPage final : public StyleChooserPage {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
VectorBrushStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {
|
|
Shinya Kitaoka |
120a6e |
m_chipSize = QSize(60, 25);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
static CustomStyleManager *styleManager();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
bool event(QEvent *e) override;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void showEvent(QShowEvent *) override {
|
|
Shinya Kitaoka |
120a6e |
connect(styleManager(), SIGNAL(patternAdded()), this, SLOT(computeSize()));
|
|
Shinya Kitaoka |
120a6e |
styleManager()->loadItems();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
void hideEvent(QHideEvent *) override {
|
|
Shinya Kitaoka |
120a6e |
disconnect(styleManager(), SIGNAL(patternAdded()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(computeSize()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
bool loadIfNeeded() override { return false; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
int getChipCount() const override {
|
|
Shinya Kitaoka |
38fd86 |
return styleManager()->getPatternCount() + 1;
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void drawChip(QPainter &p, QRect rect, int index) override;
|
|
Shinya Kitaoka |
473e70 |
void onSelect(int index) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager *VectorBrushStyleChooserPage::styleManager() {
|
|
Shinya Kitaoka |
120a6e |
static CustomStyleManager theManager(TFilePath("vector brushes"), "*.pli",
|
|
Shinya Kitaoka |
120a6e |
QSize(60, 25));
|
|
Shinya Kitaoka |
120a6e |
return &theManager;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool VectorBrushStyleChooserPage::event(QEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
// Intercept tooltip events
|
|
Shinya Kitaoka |
120a6e |
if (e->type() != QEvent::ToolTip) return StyleChooserPage::event(e);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// see StyleChooserPage::paintEvent
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager *manager = styleManager();
|
|
Shinya Kitaoka |
120a6e |
QHelpEvent *he = static_cast<qhelpevent *="">(e);</qhelpevent>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int chipIdx = posToIndex(he->pos()), chipCount = getChipCount();
|
|
Shinya Kitaoka |
120a6e |
if (chipIdx < 0 || chipIdx >= chipCount) return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (chipIdx > 0) {
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager::PatternData pattern = manager->getPattern(chipIdx - 1);
|
|
Shinya Kitaoka |
120a6e |
QToolTip::showText(he->globalPos(),
|
|
Shinya Kitaoka |
120a6e |
QString::fromStdString(pattern.m_patternName));
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
shun-iwasawa |
199e29 |
QToolTip::showText(
|
|
shun-iwasawa |
199e29 |
he->globalPos(),
|
|
shun-iwasawa |
199e29 |
QObject::tr("Plain color", "VectorBrushStyleChooserPage"));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void VectorBrushStyleChooserPage::drawChip(QPainter &p, QRect rect, int index) {
|
|
Shinya Kitaoka |
120a6e |
if (index == 0) {
|
|
Shinya Kitaoka |
120a6e |
static QImage noSpecialStyleImage(":Resources/no_vectorbrush.png");
|
|
Shinya Kitaoka |
120a6e |
p.drawImage(rect, noSpecialStyleImage);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= index && index < getChipCount());
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager::PatternData pattern =
|
|
Shinya Kitaoka |
120a6e |
styleManager()->getPattern(index - 1);
|
|
Shinya Kitaoka |
120a6e |
p.drawImage(rect, *pattern.m_image);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void VectorBrushStyleChooserPage::onSelect(int index) {
|
|
Shinya Kitaoka |
120a6e |
if (index < 0 || index >= getChipCount()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (index > 0) {
|
|
Shinya Kitaoka |
120a6e |
--index;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
CustomStyleManager::PatternData pattern = styleManager()->getPattern(index);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_currentIndex < 0) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string name = pattern.m_patternName;
|
|
Shinya Kitaoka |
120a6e |
assert(pattern.m_isVector);
|
|
Shinya Kitaoka |
120a6e |
if (!pattern.m_isVector) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TVectorBrushStyle cs(name);
|
|
Shinya Kitaoka |
120a6e |
emit styleSelected(cs);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
TSolidColorStyle cs(TPixel32::Black);
|
|
Shinya Kitaoka |
120a6e |
emit styleSelected(cs);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// TextureStyleChooser definition
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct Texture {
|
|
Shinya Kitaoka |
120a6e |
TRasterP m_raster;
|
|
Shinya Kitaoka |
120a6e |
QString m_name;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class TextureStyleChooserPage final : public StyleChooserPage {
|
|
Shinya Kitaoka |
120a6e |
static std::vector<texture> m_textures;</texture>
|
|
Shinya Kitaoka |
120a6e |
static bool m_loaded;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TextureStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
bool loadIfNeeded() override {
|
|
Shinya Kitaoka |
120a6e |
if (!m_loaded) {
|
|
Shinya Kitaoka |
120a6e |
loadItems();
|
|
Shinya Kitaoka |
120a6e |
m_loaded = true;
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getChipCount() const override { return m_textures.size(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
static void loadTexture(const TFilePath &fp);
|
|
Shinya Kitaoka |
120a6e |
static void loadItems();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void drawChip(QPainter &p, QRect rect, int index) override {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= index && index < getChipCount());
|
|
Shinya Kitaoka |
120a6e |
p.drawImage(rect, rasterToQImage(m_textures[index].m_raster));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void onSelect(int index) override;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
bool event(QEvent *e) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<texture> TextureStyleChooserPage::m_textures;</texture>
|
|
Toshihiro Shimizu |
890ddd |
bool TextureStyleChooserPage::m_loaded(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TextureStyleChooserPage::loadTexture(const TFilePath &fp) {
|
|
Shinya Kitaoka |
120a6e |
if (fp == TFilePath()) {
|
|
Shinya Kitaoka |
120a6e |
TRaster32P ras(25, 25);
|
|
Shinya Kitaoka |
120a6e |
TTextureStyle::fillCustomTextureIcon(ras);
|
|
Shinya Kitaoka |
120a6e |
// ras->fill(TPixel::Blue);
|
|
Shinya Kitaoka |
120a6e |
Texture customText = {ras, QString("")};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_textures.push_back(customText);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras;
|
|
Shinya Kitaoka |
120a6e |
TImageReader::load(fp, ras);
|
|
Shinya Kitaoka |
120a6e |
if (!ras || ras->getLx() < 2 || ras->getLy() < 2) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRaster32P ras32 = ras;
|
|
Shinya Kitaoka |
120a6e |
if (!ras32) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TDimension d(2, 2);
|
|
Shinya Kitaoka |
120a6e |
while (d.lx < 256 && d.lx * 2 <= ras32->getLx()) d.lx *= 2;
|
|
Shinya Kitaoka |
120a6e |
while (d.ly < 256 && d.ly * 2 <= ras32->getLy()) d.ly *= 2;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRaster32P texture;
|
|
Shinya Kitaoka |
120a6e |
if (d == ras32->getSize())
|
|
Shinya Kitaoka |
120a6e |
texture = ras32;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
texture = TRaster32P(d);
|
|
Shinya Kitaoka |
120a6e |
TScale sc((double)texture->getLx() / ras32->getLx(),
|
|
Shinya Kitaoka |
120a6e |
(double)texture->getLy() / ras32->getLy());
|
|
Shinya Kitaoka |
120a6e |
TRop::resample(texture, ras32, sc);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Texture text = {texture, QString::fromStdWString(fp.getLevelNameW())};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_textures.push_back(text);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TextureStyleChooserPage::loadItems() {
|
|
Shinya Kitaoka |
120a6e |
m_textures.clear();
|
|
Shinya Kitaoka |
120a6e |
if (getRootPath() == TFilePath()) return;
|
|
Shinya Kitaoka |
120a6e |
TFilePath texturePath = getRootPath() + "textures";
|
|
Shinya Kitaoka |
120a6e |
TFilePathSet fps;
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
fps = TSystem::readDirectory(texturePath);
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (fps.empty()) return;
|
|
Shinya Kitaoka |
120a6e |
int count = 0;
|
|
Shinya Kitaoka |
120a6e |
for (TFilePathSet::iterator it = fps.begin(); it != fps.end(); it++)
|
|
Shinya Kitaoka |
120a6e |
if (TFileType::getInfo(*it) == TFileType::RASTER_IMAGE) {
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
loadTexture(*it);
|
|
Shinya Kitaoka |
120a6e |
++count;
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
loadTexture(TFilePath()); // custom texture
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TextureStyleChooserPage::onSelect(int index) {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= index && index < (int)m_textures.size());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TTextureStyle style(m_textures[index].m_raster,
|
|
Shinya Kitaoka |
120a6e |
TFilePath(m_textures[index].m_name.toStdWString()));
|
|
Shinya Kitaoka |
120a6e |
emit styleSelected(style);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TextureStyleChooserPage::event(QEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
if (e->type() == QEvent::ToolTip) {
|
|
Shinya Kitaoka |
120a6e |
QHelpEvent *helpEvent = dynamic_cast<qhelpevent *="">(e);</qhelpevent>
|
|
Shinya Kitaoka |
120a6e |
QString toolTip;
|
|
Shinya Kitaoka |
120a6e |
QPoint pos = helpEvent->pos();
|
|
Shinya Kitaoka |
120a6e |
int index = posToIndex(pos);
|
|
Shinya Kitaoka |
120a6e |
if (index >= 0 && index < (int)m_textures.size()) {
|
|
Shinya Kitaoka |
120a6e |
toolTip = m_textures[index].m_name;
|
|
shun-iwasawa |
199e29 |
QToolTip::showText(
|
|
shun-iwasawa |
199e29 |
helpEvent->globalPos(),
|
|
shun-iwasawa |
199e29 |
toolTip != QString()
|
|
shun-iwasawa |
199e29 |
? toolTip
|
|
shun-iwasawa |
199e29 |
: QObject::tr("Custom Texture", "TextureStyleChooserPage"));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
e->accept();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return StyleChooserPage::event(e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
|
bf1d82 |
// MyPaintBrushStyleChooserPage definition
|
|
|
bf1d82 |
//*****************************************************************************
|
|
|
bf1d82 |
|
|
|
bf1d82 |
class MyPaintBrushStyleChooserPage final : public StyleChooserPage {
|
|
|
bf1d82 |
public:
|
|
|
bf1d82 |
struct Brush {
|
|
|
bf1d82 |
TRasterP m_raster;
|
|
|
bf1d82 |
QString m_name;
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
|
bf1d82 |
private:
|
|
|
bf1d82 |
static std::vector<tmypaintbrushstyle> m_brushes;</tmypaintbrushstyle>
|
|
|
bf1d82 |
|
|
|
bf1d82 |
public:
|
|
shun_iwasawa |
3cc41f |
MyPaintBrushStyleChooserPage(QWidget *parent = 0) : StyleChooserPage(parent) {
|
|
shun_iwasawa |
3cc41f |
m_chipSize = QSize(64, 64);
|
|
shun_iwasawa |
3cc41f |
}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
bool loadIfNeeded() override {
|
|
|
bf1d82 |
static bool m_loaded = false;
|
|
|
bf1d82 |
if (!m_loaded) {
|
|
|
bf1d82 |
loadItems();
|
|
|
bf1d82 |
m_loaded = true;
|
|
|
bf1d82 |
return true;
|
|
|
bf1d82 |
} else
|
|
|
bf1d82 |
return false;
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
shun_iwasawa |
3cc41f |
int getChipCount() const override { return m_brushes.size() + 1; }
|
|
|
bf1d82 |
|
|
|
bf1d82 |
static void loadItems();
|
|
|
bf1d82 |
|
|
|
bf1d82 |
void drawChip(QPainter &p, QRect rect, int index) override {
|
|
|
bf1d82 |
assert(0 <= index && index <= (int)m_brushes.size());
|
|
|
bf1d82 |
static QImage noStyleImage(":Resources/no_mypaintbrush.png");
|
|
shun_iwasawa |
3cc41f |
p.drawImage(rect, index == 0
|
|
shun_iwasawa |
3cc41f |
? noStyleImage
|
|
shun_iwasawa |
3cc41f |
: rasterToQImage(m_brushes[index - 1].getPreview()));
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
void onSelect(int index) override {
|
|
|
bf1d82 |
assert(0 <= index && index <= (int)m_brushes.size());
|
|
|
bf1d82 |
static TSolidColorStyle noStyle(TPixel32::Black);
|
|
|
bf1d82 |
if (index == 0) {
|
|
|
bf1d82 |
emit styleSelected(noStyle);
|
|
|
bf1d82 |
} else {
|
|
shun_iwasawa |
3cc41f |
emit styleSelected(m_brushes[index - 1]);
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
bool event(QEvent *e) override {
|
|
|
bf1d82 |
static TSolidColorStyle noStyle(TPixel32::Black);
|
|
|
bf1d82 |
if (e->type() == QEvent::ToolTip) {
|
|
|
bf1d82 |
QHelpEvent *helpEvent = dynamic_cast<qhelpevent *="">(e);</qhelpevent>
|
|
|
bf1d82 |
QString toolTip;
|
|
|
bf1d82 |
QPoint pos = helpEvent->pos();
|
|
|
bf1d82 |
int index = posToIndex(pos);
|
|
|
bf1d82 |
if (index == 0) {
|
|
shun-iwasawa |
199e29 |
toolTip = QObject::tr("Plain color", "MyPaintBrushStyleChooserPage");
|
|
shun_iwasawa |
3cc41f |
} else if (index > 0 && index <= (int)m_brushes.size()) {
|
|
shun_iwasawa |
3cc41f |
toolTip = m_brushes[index - 1].getPath().getQString();
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
QToolTip::showText(helpEvent->globalPos(), toolTip);
|
|
|
bf1d82 |
e->accept();
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
return StyleChooserPage::event(e);
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
};
|
|
|
bf1d82 |
|
|
|
bf1d82 |
//-----------------------------------------------------------------------------
|
|
|
bf1d82 |
|
|
|
bf1d82 |
std::vector<tmypaintbrushstyle> MyPaintBrushStyleChooserPage::m_brushes;</tmypaintbrushstyle>
|
|
|
bf1d82 |
|
|
|
bf1d82 |
//-----------------------------------------------------------------------------
|
|
|
bf1d82 |
|
|
|
bf1d82 |
void MyPaintBrushStyleChooserPage::loadItems() {
|
|
|
bf1d82 |
m_brushes.clear();
|
|
|
bf1d82 |
std::set<tfilepath> brushFiles;</tfilepath>
|
|
|
bf1d82 |
|
|
|
bf1d82 |
TFilePathSet dirs = TMyPaintBrushStyle::getBrushesDirs();
|
|
shun_iwasawa |
3cc41f |
for (TFilePathSet::iterator i = dirs.begin(); i != dirs.end(); ++i) {
|
|
|
bf1d82 |
TFileStatus fs(*i);
|
|
|
bf1d82 |
if (fs.doesExist() && fs.isDirectory()) {
|
|
|
bf1d82 |
TFilePathSet files = TSystem::readDirectoryTree(*i, false, true);
|
|
shun_iwasawa |
3cc41f |
for (TFilePathSet::iterator j = files.begin(); j != files.end(); ++j)
|
|
|
bf1d82 |
if (j->getType() == TMyPaintBrushStyle::getBrushType())
|
|
|
bf1d82 |
brushFiles.insert(*j - *i);
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
// reserve memory to avoid reallocation
|
|
|
bf1d82 |
m_brushes.reserve(brushFiles.size());
|
|
shun_iwasawa |
3cc41f |
for (std::set<tfilepath>::iterator i = brushFiles.begin();</tfilepath>
|
|
shun_iwasawa |
3cc41f |
i != brushFiles.end(); ++i)
|
|
|
bf1d82 |
m_brushes.push_back(TMyPaintBrushStyle(*i));
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// SpecialStyleChooser definition
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class SpecialStyleChooserPage final : public StyleChooserPage {
|
|
Shinya Kitaoka |
120a6e |
static std::vector<std::pair<int, *="" qimage="">> m_customStyles;</std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
static bool m_loaded;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SpecialStyleChooserPage(QWidget *parent = 0,
|
|
Shinya Kitaoka |
120a6e |
const TFilePath &rootDir = TFilePath())
|
|
Shinya Kitaoka |
120a6e |
: StyleChooserPage(parent) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
bool loadIfNeeded() override {
|
|
Shinya Kitaoka |
120a6e |
if (!m_loaded) {
|
|
Shinya Kitaoka |
120a6e |
loadItems();
|
|
Shinya Kitaoka |
120a6e |
m_loaded = true;
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getChipCount() const override { return m_customStyles.size(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void loadItems();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void drawChip(QPainter &p, QRect rect, int index) override;
|
|
Shinya Kitaoka |
473e70 |
void onSelect(int index) override;
|
|
Shinya Kitaoka |
473e70 |
bool event(QEvent *e) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::pair<int, *="" qimage="">> SpecialStyleChooserPage::m_customStyles;</std::pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
bool SpecialStyleChooserPage::m_loaded(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SpecialStyleChooserPage::loadItems() {
|
|
Shinya Kitaoka |
120a6e |
std::vector<int> tags;</int>
|
|
Shinya Kitaoka |
120a6e |
TColorStyle::getAllTags(tags);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int chipCount = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int j = 0; j < (int)tags.size(); j++) {
|
|
Shinya Kitaoka |
120a6e |
int tagId = tags[j];
|
|
Shinya Kitaoka |
120a6e |
if (tagId == 3 || // solid color
|
|
Shinya Kitaoka |
120a6e |
tagId == 4 || // texture
|
|
Shinya Kitaoka |
120a6e |
tagId == 100 || // obsolete imagepattern id
|
|
Shinya Kitaoka |
120a6e |
tagId == 2000 || // imagepattern
|
|
Shinya Kitaoka |
120a6e |
tagId == 2800 || // imagepattern
|
|
Shinya Kitaoka |
120a6e |
tagId == 2001 || // cleanup
|
|
Shinya Kitaoka |
120a6e |
tagId == 2002 || // ??
|
|
|
bf1d82 |
tagId == 3000 || // vector brush
|
|
|
bf1d82 |
tagId == 4001 // mypaint brush
|
|
shun-iwasawa |
e40777 |
)
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = TColorStyle::create(tagId);
|
|
Shinya Kitaoka |
120a6e |
if (style->isRasterStyle()) {
|
|
Shinya Kitaoka |
120a6e |
delete style;
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TDimension chipSize(getChipSize().width(), getChipSize().height());
|
|
Shinya Kitaoka |
120a6e |
QImage *image = new QImage(rasterToQImage(style->getIcon(chipSize), false));
|
|
Shinya Kitaoka |
120a6e |
m_customStyles.push_back(std::make_pair(tagId, image));
|
|
Shinya Kitaoka |
120a6e |
delete style;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SpecialStyleChooserPage::drawChip(QPainter &p, QRect rect, int index) {
|
|
Shinya Kitaoka |
120a6e |
if (index == 0) {
|
|
Shinya Kitaoka |
120a6e |
static QImage noSpecialStyleImage(":Resources/no_specialstyle.png");
|
|
Shinya Kitaoka |
120a6e |
p.drawImage(rect, noSpecialStyleImage);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
int j = index - 1;
|
|
Shinya Kitaoka |
120a6e |
if (0 <= j && j < (int)m_customStyles.size())
|
|
Shinya Kitaoka |
120a6e |
p.drawImage(rect, *m_customStyles[j].second);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
p.fillRect(rect, QBrush(QColor(255, 0, 0)));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SpecialStyleChooserPage::onSelect(int index) {
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= index && index < (int)m_customStyles.size());
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = 0;
|
|
Shinya Kitaoka |
120a6e |
if (m_currentIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
if (index == 0)
|
|
Shinya Kitaoka |
120a6e |
cs = new TSolidColorStyle(TPixel32::Black);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
int j = index - 1;
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= j && j < (int)m_customStyles.size());
|
|
Shinya Kitaoka |
120a6e |
int tagId = m_customStyles[j].first;
|
|
Shinya Kitaoka |
120a6e |
cs = TColorStyle::create(tagId);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
emit styleSelected(*cs);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool SpecialStyleChooserPage::event(QEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
if (e->type() == QEvent::ToolTip) {
|
|
Shinya Kitaoka |
120a6e |
QHelpEvent *helpEvent = dynamic_cast<qhelpevent *="">(e);</qhelpevent>
|
|
Shinya Kitaoka |
120a6e |
QString toolTip;
|
|
Shinya Kitaoka |
120a6e |
QPoint pos = helpEvent->pos();
|
|
Shinya Kitaoka |
120a6e |
int index = posToIndex(pos);
|
|
Shinya Kitaoka |
120a6e |
if (index == 0)
|
|
shun-iwasawa |
199e29 |
toolTip = QObject::tr("Plain color", "SpecialStyleChooserPage");
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
int j = index - 1;
|
|
Shinya Kitaoka |
120a6e |
if (0 <= j && j < (int)m_customStyles.size()) {
|
|
Shinya Kitaoka |
120a6e |
int tagId = m_customStyles[j].first;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = TColorStyle::create(tagId);
|
|
Shinya Kitaoka |
120a6e |
if (cs) {
|
|
Shinya Kitaoka |
120a6e |
toolTip = cs->getDescription();
|
|
Shinya Kitaoka |
120a6e |
delete cs;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (toolTip != "")
|
|
Shinya Kitaoka |
120a6e |
QToolTip::showText(helpEvent->globalPos(), toolTip);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
QToolTip::hideText();
|
|
Shinya Kitaoka |
120a6e |
e->accept();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return StyleChooserPage::event(e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// SettingBox
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
SettingBox::SettingBox(QWidget *parent, int index)
|
|
Toshihiro Shimizu |
890ddd |
: QWidget(parent)
|
|
Toshihiro Shimizu |
890ddd |
, m_index(index)
|
|
Toshihiro Shimizu |
890ddd |
, m_style(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout* hLayout = new QHBoxLayout(this);
|
|
Shinya Kitaoka |
120a6e |
hLayout->setSpacing(5);
|
|
Shinya Kitaoka |
120a6e |
hLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addSpacing(10);
|
|
Shinya Kitaoka |
120a6e |
m_name = new QLabel(this);
|
|
Shinya Kitaoka |
120a6e |
m_name->setFixedSize(82,20);
|
|
Shinya Kitaoka |
120a6e |
m_name->setStyleSheet("border: 0px;");
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_name,0);
|
|
Shinya Kitaoka |
120a6e |
m_doubleField = new DoubleField(this, true);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_doubleField,1);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addSpacing(10);
|
|
Shinya Kitaoka |
120a6e |
bool ret = connect(m_doubleField, SIGNAL(valueChanged(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValueChanged(bool)));
|
|
Toshihiro Shimizu |
890ddd |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
setLayout(hLayout);
|
|
Shinya Kitaoka |
120a6e |
setFixedHeight(22);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void SettingBox::setParameters(TColorStyle* cs)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
if(!cs)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_style = cs;
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if(cs->getParamCount() == 0 || m_index<0 ||
|
|
Shinya Kitaoka |
120a6e |
cs->getParamCount()<=m_index)
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
QString paramName = cs->getParamNames(m_index);
|
|
Shinya Kitaoka |
120a6e |
m_name->setText(paramName);
|
|
Toshihiro Shimizu |
890ddd |
double newValue = cs->getParamValue(TColorStyle::double_tag(), m_index);
|
|
Shinya Kitaoka |
120a6e |
double value = m_doubleField->getValue();
|
|
Shinya Kitaoka |
120a6e |
m_style = cs;
|
|
Shinya Kitaoka |
120a6e |
if(value != newValue)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
double min=0, max=1;
|
|
Shinya Kitaoka |
120a6e |
cs->getParamRange(m_index,min,max);
|
|
Shinya Kitaoka |
120a6e |
m_doubleField->setValues(newValue, min, max);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TCleanupStyle* cleanupStyle = dynamic_cast<tcleanupstyle*>(cs);</tcleanupstyle*>
|
|
Shinya Kitaoka |
120a6e |
if(paramName == "Contrast" && cleanupStyle)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
if(!cleanupStyle->isContrastEnabled())
|
|
Shinya Kitaoka |
120a6e |
m_doubleField->setEnabled(false);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
m_doubleField->setEnabled(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void SettingBox::setColorStyleParam(double value, bool isDragging)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle* style = m_style;
|
|
Toshihiro Shimizu |
890ddd |
assert(style && m_index < style->getParamCount());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double min = 0.0, max = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
style->getParamRange(m_index, min, max);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
style->setParamValue(m_index, tcrop(value, min, max));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
emit valueChanged(*style, isDragging);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void SettingBox::onValueChanged(bool isDragging)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
if(!m_style || m_style->getParamCount() == 0)
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double value = m_doubleField->getValue();
|
|
Shinya Kitaoka |
120a6e |
if(isDragging && m_style->getParamValue(TColorStyle::double_tag(),
|
|
Shinya Kitaoka |
120a6e |
m_index) == value)
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setColorStyleParam(value, isDragging);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// SettingsPage implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
SettingsPage::SettingsPage(QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: QScrollArea(parent), m_updating(false) {
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setObjectName("styleEditorPage"); // It is necessary for the styleSheet
|
|
Shinya Kitaoka |
120a6e |
setFrameStyle(QFrame::StyledPanel);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
Shinya Kitaoka |
120a6e |
setWidgetResizable(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Build the scrolled widget
|
|
Shinya Kitaoka |
120a6e |
QFrame *paramsContainer = new QFrame(this);
|
|
Shinya Kitaoka |
120a6e |
setWidget(paramsContainer);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *paramsContainerLayout = new QVBoxLayout(this);
|
|
shun-iwasawa |
2a343c |
paramsContainerLayout->setMargin(10);
|
|
shun-iwasawa |
2a343c |
paramsContainerLayout->setSpacing(10);
|
|
Shinya Kitaoka |
120a6e |
paramsContainer->setLayout(paramsContainerLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Add a vertical layout to store the "autofill" checkbox widgets
|
|
shun-iwasawa |
2a343c |
m_autoFillCheckBox = new QCheckBox(tr("Autopaint for Lines"), this);
|
|
shun-iwasawa |
2a343c |
paramsContainerLayout->addWidget(m_autoFillCheckBox, 0,
|
|
shun-iwasawa |
2a343c |
Qt::AlignLeft | Qt::AlignVCenter);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
2a343c |
ret = connect(m_autoFillCheckBox, SIGNAL(stateChanged(int)), this,
|
|
shun-iwasawa |
2a343c |
SLOT(onAutofillChanged()));
|
|
shun-iwasawa |
2a343c |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Prepare the style parameters layout
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout = new QGridLayout;
|
|
shun-iwasawa |
2a343c |
m_paramsLayout->setMargin(0);
|
|
shun-iwasawa |
2a343c |
m_paramsLayout->setVerticalSpacing(8);
|
|
shun-iwasawa |
2a343c |
m_paramsLayout->setHorizontalSpacing(5);
|
|
Shinya Kitaoka |
120a6e |
paramsContainerLayout->addLayout(m_paramsLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
2a343c |
paramsContainerLayout->addStretch(1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SettingsPage::enableAutopaintToggle(bool enabled) {
|
|
shun-iwasawa |
2a343c |
m_autoFillCheckBox->setVisible(enabled);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SettingsPage::setStyle(const TColorStyleP &editedStyle) {
|
|
Shinya Kitaoka |
120a6e |
struct locals {
|
|
Shinya Kitaoka |
120a6e |
inline static void clearLayout(QLayout *layout) {
|
|
Shinya Kitaoka |
120a6e |
QLayoutItem *item;
|
|
Shinya Kitaoka |
120a6e |
while ((item = layout->takeAt(0)) != 0) {
|
|
Shinya Kitaoka |
120a6e |
delete item->layout();
|
|
Shinya Kitaoka |
120a6e |
delete item->spacerItem();
|
|
Shinya Kitaoka |
120a6e |
delete item->widget();
|
|
Shinya Kitaoka |
120a6e |
delete item;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}; // locals
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// NOTE: Layout reubilds must be avoided whenever possible. In particular, be
|
|
Shinya Kitaoka |
120a6e |
// warned that this
|
|
Shinya Kitaoka |
120a6e |
// function may be invoked when signals emitted from this function are still
|
|
Shinya Kitaoka |
120a6e |
// "flying"...
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool clearLayout =
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle &&
|
|
Shinya Kitaoka |
120a6e |
!(editedStyle && typeid(*m_editedStyle) == typeid(*editedStyle));
|
|
Shinya Kitaoka |
120a6e |
bool buildLayout =
|
|
Shinya Kitaoka |
120a6e |
editedStyle &&
|
|
Shinya Kitaoka |
120a6e |
!(m_editedStyle && typeid(*m_editedStyle) == typeid(*editedStyle));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle = editedStyle;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (clearLayout) locals::clearLayout(m_paramsLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (buildLayout) {
|
|
Shinya Kitaoka |
120a6e |
assert(m_paramsLayout->count() == 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Assign new settings widgets - one label/editor for each parameter
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int p, pCount = editedStyle->getParamCount();
|
|
Shinya Kitaoka |
120a6e |
for (p = 0; p != pCount; ++p) {
|
|
Shinya Kitaoka |
120a6e |
// Assign label
|
|
Shinya Kitaoka |
120a6e |
QLabel *label = new QLabel(editedStyle->getParamNames(p));
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->addWidget(label, p, 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Assign parameter
|
|
Shinya Kitaoka |
120a6e |
switch (editedStyle->getParamType(p)) {
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::BOOL: {
|
|
Shinya Kitaoka |
120a6e |
QCheckBox *checkBox = new QCheckBox;
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->addWidget(checkBox, p, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ret = QObject::connect(checkBox, SIGNAL(toggled(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValueChanged())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::INT: {
|
|
Shinya Kitaoka |
120a6e |
DVGui::IntField *intField = new DVGui::IntField;
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->addWidget(intField, p, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int min, max;
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamRange(p, min, max);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
intField->setRange(min, max);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ret = QObject::connect(intField, SIGNAL(valueChanged(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValueChanged(bool))) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::ENUM: {
|
|
Shinya Kitaoka |
120a6e |
QComboBox *comboBox = new QComboBox;
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->addWidget(comboBox, p, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QStringList items;
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamRange(p, items);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
comboBox->addItems(items);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ret = QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValueChanged())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::DOUBLE: {
|
|
Shinya Kitaoka |
120a6e |
DVGui::DoubleField *doubleField = new DVGui::DoubleField;
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->addWidget(doubleField, p, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double min, max;
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamRange(p, min, max);
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
doubleField->setRange(min, max);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ret = QObject::connect(doubleField, SIGNAL(valueChanged(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValueChanged(bool))) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::FILEPATH: {
|
|
Shinya Kitaoka |
120a6e |
DVGui::FileField *fileField = new DVGui::FileField;
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->addWidget(fileField, p, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QStringList extensions;
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamRange(p, extensions);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
fileField->setFileMode(QFileDialog::AnyFile);
|
|
Shinya Kitaoka |
120a6e |
fileField->setFilters(extensions);
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
fileField->setPath(QString::fromStdWString(
|
|
Shinya Kitaoka |
120a6e |
editedStyle->getParamValue(TColorStyle::TFilePath_tag(), p)
|
|
Shinya Kitaoka |
120a6e |
.getWideString()));
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
ret = QObject::connect(fileField, SIGNAL(pathChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onValueChanged())) &&
|
|
Shinya Kitaoka |
120a6e |
ret;
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
bf1d82 |
// "reset to default" button
|
|
|
bf1d82 |
if (m_editedStyle->hasParamDefault(p)) {
|
|
|
bf1d82 |
QPushButton *pushButton = new QPushButton;
|
|
|
bf1d82 |
pushButton->setToolTip(tr("Reset to default"));
|
|
shun_iwasawa |
3cc41f |
pushButton->setIcon(createQIcon("delete"));
|
|
|
bf1d82 |
m_paramsLayout->addWidget(pushButton, p, 2);
|
|
|
bf1d82 |
ret = QObject::connect(pushButton, SIGNAL(clicked(bool)), this,
|
|
|
bf1d82 |
SLOT(onValueReset())) &&
|
|
|
bf1d82 |
ret;
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
updateValues();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SettingsPage::updateValues() {
|
|
Shinya Kitaoka |
120a6e |
if (!m_editedStyle) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
struct Updating {
|
|
Shinya Kitaoka |
120a6e |
SettingsPage *m_this; // Prevent 'param changed' signals from being
|
|
Shinya Kitaoka |
120a6e |
~Updating() {
|
|
Shinya Kitaoka |
120a6e |
m_this->m_updating = false;
|
|
Shinya Kitaoka |
120a6e |
} // sent when updating editor widgets - this is
|
|
Shinya Kitaoka |
120a6e |
} updating = {(m_updating = true, this)}; // just a view REFRESH function.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Deal with the autofill
|
|
Shinya Kitaoka |
120a6e |
m_autoFillCheckBox->setChecked(m_editedStyle->getFlags() & 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int p, pCount = m_editedStyle->getParamCount();
|
|
Shinya Kitaoka |
120a6e |
for (p = 0; p != pCount; ++p) {
|
|
|
bf1d82 |
// Update state of "reset to default" button
|
|
|
bf1d82 |
if (m_editedStyle->hasParamDefault(p)) {
|
|
|
bf1d82 |
QPushButton *pushButton = static_cast<qpushbutton *="">(</qpushbutton>
|
|
|
bf1d82 |
m_paramsLayout->itemAtPosition(p, 2)->widget());
|
|
|
bf1d82 |
pushButton->setEnabled(m_editedStyle->isParamDefault(p));
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
Shinya Kitaoka |
120a6e |
// Update editor values
|
|
Shinya Kitaoka |
120a6e |
switch (m_editedStyle->getParamType(p)) {
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::BOOL: {
|
|
Shinya Kitaoka |
120a6e |
QCheckBox *checkBox = static_cast<qcheckbox *="">(</qcheckbox>
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->itemAtPosition(p, 1)->widget());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
checkBox->setChecked(
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamValue(TColorStyle::bool_tag(), p));
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::INT: {
|
|
Shinya Kitaoka |
120a6e |
DVGui::IntField *intField = static_cast<dvgui::intfield *="">(</dvgui::intfield>
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->itemAtPosition(p, 1)->widget());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
intField->setValue(
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamValue(TColorStyle::int_tag(), p));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::ENUM: {
|
|
Shinya Kitaoka |
120a6e |
QComboBox *comboBox = static_cast<qcombobox *="">(</qcombobox>
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->itemAtPosition(p, 1)->widget());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
comboBox->setCurrentIndex(
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamValue(TColorStyle::int_tag(), p));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::DOUBLE: {
|
|
Shinya Kitaoka |
120a6e |
DVGui::DoubleField *doubleField = static_cast<dvgui::doublefield *="">(</dvgui::doublefield>
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->itemAtPosition(p, 1)->widget());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
doubleField->setValue(
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamValue(TColorStyle::double_tag(), p));
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::FILEPATH: {
|
|
Shinya Kitaoka |
120a6e |
DVGui::FileField *fileField = static_cast<dvgui::filefield *="">(</dvgui::filefield>
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout->itemAtPosition(p, 1)->widget());
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
fileField->setPath(QString::fromStdWString(
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getParamValue(TColorStyle::TFilePath_tag(), p)
|
|
Shinya Kitaoka |
120a6e |
.getWideString()));
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SettingsPage::onAutofillChanged() {
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setFlags((unsigned int)(m_autoFillCheckBox->isChecked()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_updating)
|
|
Shinya Kitaoka |
120a6e |
emit paramStyleChanged(false); // Forward the signal to the style editor
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
bf1d82 |
int SettingsPage::getParamIndex(const QWidget *widget) {
|
|
|
bf1d82 |
int p, pCount = m_paramsLayout->rowCount();
|
|
|
bf1d82 |
for (p = 0; p != pCount; ++p)
|
|
shun_iwasawa |
3cc41f |
for (int c = 0; c < 3; ++c)
|
|
|
bf1d82 |
if (QLayoutItem *item = m_paramsLayout->itemAtPosition(p, c))
|
|
shun_iwasawa |
3cc41f |
if (item->widget() == widget) return p;
|
|
|
bf1d82 |
return -1;
|
|
|
bf1d82 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
|
bf1d82 |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
|
bf1d82 |
void SettingsPage::onValueReset() {
|
|
|
bf1d82 |
assert(m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
|
|
|
bf1d82 |
// Extract the parameter index
|
|
|
bf1d82 |
QWidget *senderWidget = static_cast<qwidget *="">(sender());</qwidget>
|
|
|
bf1d82 |
int p = getParamIndex(senderWidget);
|
|
Shinya Kitaoka |
120a6e |
|
|
|
bf1d82 |
assert(0 <= p && p < m_editedStyle->getParamCount());
|
|
|
bf1d82 |
m_editedStyle->setParamDefault(p);
|
|
|
bf1d82 |
|
|
|
bf1d82 |
// Forward the signal to the style editor
|
|
|
bf1d82 |
if (!m_updating) emit paramStyleChanged(false);
|
|
|
bf1d82 |
}
|
|
|
bf1d82 |
|
|
|
bf1d82 |
//-----------------------------------------------------------------------------
|
|
|
bf1d82 |
|
|
|
bf1d82 |
void SettingsPage::onValueChanged(bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
assert(m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Extract the parameter index
|
|
Shinya Kitaoka |
120a6e |
QWidget *senderWidget = static_cast<qwidget *="">(sender());</qwidget>
|
|
|
bf1d82 |
int p = getParamIndex(senderWidget);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= p && p < m_editedStyle->getParamCount());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Update the style's parameter value
|
|
Shinya Kitaoka |
120a6e |
switch (m_editedStyle->getParamType(p)) {
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::BOOL:
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setParamValue(
|
|
Shinya Kitaoka |
120a6e |
p, static_cast<qcheckbox *="">(senderWidget)->isChecked());</qcheckbox>
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::INT:
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setParamValue(
|
|
Shinya Kitaoka |
120a6e |
p, static_cast<dvgui::intfield *="">(senderWidget)->getValue());</dvgui::intfield>
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::ENUM:
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setParamValue(
|
|
Shinya Kitaoka |
120a6e |
p, static_cast<qcombobox *="">(senderWidget)->currentIndex());</qcombobox>
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::DOUBLE:
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setParamValue(
|
|
Shinya Kitaoka |
120a6e |
p, static_cast<dvgui::doublefield *="">(senderWidget)->getValue());</dvgui::doublefield>
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case TColorStyle::FILEPATH: {
|
|
Shinya Kitaoka |
120a6e |
const QString &string =
|
|
Shinya Kitaoka |
120a6e |
static_cast<dvgui::filefield *="">(senderWidget)->getPath();</dvgui::filefield>
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setParamValue(p, TFilePath(string.toStdWString()));
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Forward the signal to the style editor
|
|
Shinya Kitaoka |
120a6e |
if (!m_updating) emit paramStyleChanged(isDragging);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *makeChooserPage(QWidget *chooser) {
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *scrollArea = new QScrollArea();
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setWidgetResizable(true);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setWidget(chooser);
|
|
Shinya Kitaoka |
120a6e |
return scrollArea;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *makeChooserPageWithoutScrollBar(QWidget *chooser) {
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *scrollArea = new QScrollArea();
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setWidgetResizable(true);
|
|
Shinya Kitaoka |
120a6e |
scrollArea->setWidget(chooser);
|
|
Shinya Kitaoka |
120a6e |
return scrollArea;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// StyleEditor implementation
|
|
Toshihiro Shimizu |
890ddd |
//*****************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
StyleEditor::StyleEditor(PaletteController *paletteController, QWidget *parent)
|
|
Shinya Kitaoka |
120a6e |
: QWidget(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_paletteController(paletteController)
|
|
Shinya Kitaoka |
120a6e |
, m_paletteHandle(paletteController->getCurrentPalette())
|
|
Shinya Kitaoka |
120a6e |
, m_cleanupPaletteHandle(paletteController->getCurrentCleanupPalette())
|
|
Shinya Kitaoka |
120a6e |
, m_toolBar(0)
|
|
Shinya Kitaoka |
120a6e |
, m_enabled(false)
|
|
Shinya Kitaoka |
120a6e |
, m_enabledOnlyFirstTab(false)
|
|
Shinya Kitaoka |
120a6e |
, m_enabledFirstAndLastTab(false)
|
|
Shinya Kitaoka |
120a6e |
, m_oldStyle(0)
|
|
Jeremy Bullock |
0a2e55 |
, m_parent(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_editedStyle(0) {
|
|
Shinya Kitaoka |
120a6e |
setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
// TOGLIERE
|
|
Shinya Kitaoka |
120a6e |
TFilePath libraryPath = ToonzFolder::getLibraryFolder();
|
|
Shinya Kitaoka |
120a6e |
setRootPath(libraryPath);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_styleBar = new DVGui::TabBar(this);
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->setDrawBase(false);
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->setObjectName("StyleEditorTabBar");
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// This widget is used to set the background color of the tabBar
|
|
Shinya Kitaoka |
120a6e |
// using the styleSheet.
|
|
Shinya Kitaoka |
120a6e |
// It is also used to take 6px on the left before the tabBar
|
|
Shinya Kitaoka |
120a6e |
// and to draw the two lines on the bottom size
|
|
Shinya Kitaoka |
120a6e |
m_tabBarContainer = new TabBarContainter(this);
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector = new ColorParameterSelector(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
|
bf1d82 |
m_plainColorPage = new PlainColorPage(0);
|
|
|
bf1d82 |
m_textureStylePage = new TextureStyleChooserPage(0);
|
|
|
bf1d82 |
m_specialStylePage = new SpecialStyleChooserPage(0);
|
|
|
bf1d82 |
m_customStylePage = new CustomStyleChooserPage(0);
|
|
|
bf1d82 |
m_vectorBrushesStylePage = new VectorBrushStyleChooserPage(0);
|
|
|
bf1d82 |
m_mypaintBrushesStylePage = new MyPaintBrushStyleChooserPage(0);
|
|
|
bf1d82 |
m_settingsPage = new SettingsPage(0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QWidget *emptyPage = new StyleEditorPage(0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// For the plainColorPage and the settingsPage
|
|
Shinya Kitaoka |
120a6e |
// I create a "fake" QScrollArea (without ScrollingBar
|
|
Shinya Kitaoka |
120a6e |
// in order to use the styleSheet to stylish its background
|
|
Jeremy Bullock |
4bf672 |
QScrollArea *plainArea = makeChooserPageWithoutScrollBar(m_plainColorPage);
|
|
Jeremy Bullock |
4bf672 |
QScrollArea *textureArea = makeChooserPage(m_textureStylePage);
|
|
|
bf1d82 |
QScrollArea *mypaintBrushesArea = makeChooserPage(m_mypaintBrushesStylePage);
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *settingsArea = makeChooserPageWithoutScrollBar(m_settingsPage);
|
|
Jeremy Bullock |
4bf672 |
QScrollArea *vectorOutsideArea =
|
|
shun-iwasawa |
dfea21 |
makeChooserPageWithoutScrollBar(createVectorPage());
|
|
Jeremy Bullock |
4bf672 |
vectorOutsideArea->setMinimumWidth(50);
|
|
Jeremy Bullock |
4bf672 |
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser = new QStackedWidget(this);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(plainArea);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(textureArea);
|
|
Jeremy Bullock |
4bf672 |
m_styleChooser->addWidget(vectorOutsideArea);
|
|
|
bf1d82 |
m_styleChooser->addWidget(mypaintBrushesArea);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(settingsArea);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(makeChooserPageWithoutScrollBar(emptyPage));
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QFrame *bottomWidget = createBottomWidget();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_toolBar = new QToolBar(this);
|
|
Shinya Kitaoka |
120a6e |
m_toolBar->setMovable(false);
|
|
Shinya Kitaoka |
120a6e |
m_toolBar->setMaximumHeight(22);
|
|
Shinya Kitaoka |
120a6e |
m_toolBar->addWidget(m_colorParameterSelector);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector->setMinimumWidth(200);
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector->setFixedHeight(22);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
0a2e55 |
QMenu *menu = new QMenu();
|
|
shun-iwasawa |
e87e08 |
m_wheelAction = new QAction(tr("Wheel"), this);
|
|
shun-iwasawa |
e87e08 |
m_hsvAction = new QAction(tr("HSV"), this);
|
|
shun-iwasawa |
e87e08 |
m_alphaAction = new QAction(tr("Alpha"), this);
|
|
shun-iwasawa |
e87e08 |
m_rgbAction = new QAction(tr("RGB"), this);
|
|
Jeremy Bullock |
0a2e55 |
|
|
Jeremy Bullock |
0a2e55 |
m_wheelAction->setCheckable(true);
|
|
Jeremy Bullock |
0a2e55 |
m_hsvAction->setCheckable(true);
|
|
Jeremy Bullock |
0a2e55 |
m_alphaAction->setCheckable(true);
|
|
Jeremy Bullock |
0a2e55 |
m_rgbAction->setCheckable(true);
|
|
Jeremy Bullock |
0a2e55 |
m_wheelAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
m_hsvAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
m_alphaAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
m_rgbAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
menu->addAction(m_wheelAction);
|
|
Jeremy Bullock |
0a2e55 |
menu->addAction(m_hsvAction);
|
|
Jeremy Bullock |
0a2e55 |
menu->addAction(m_alphaAction);
|
|
Jeremy Bullock |
0a2e55 |
menu->addAction(m_rgbAction);
|
|
Jeremy Bullock |
0a2e55 |
|
|
Jeremy Bullock |
0a2e55 |
QToolButton *toolButton = new QToolButton(this);
|
|
shun-iwasawa |
2a343c |
toolButton->setIcon(createQIcon("options"));
|
|
shun-iwasawa |
2a343c |
toolButton->setFixedSize(22, 22);
|
|
Jeremy Bullock |
0a2e55 |
toolButton->setMenu(menu);
|
|
Jeremy Bullock |
0a2e55 |
toolButton->setPopupMode(QToolButton::InstantPopup);
|
|
Jeremy Bullock |
0a2e55 |
toolButton->setToolTip(tr("Show or hide parts of the Color Page."));
|
|
shun-iwasawa |
2a343c |
QToolBar *displayToolbar = new QToolBar(this);
|
|
shun-iwasawa |
2a343c |
m_toggleOrientationAction =
|
|
shun-iwasawa |
2a343c |
displayToolbar->addAction(QIcon(":Resources/orientation_h.svg"), "");
|
|
shun-iwasawa |
2a343c |
m_toggleOrientationAction->setToolTip(
|
|
Jeremy Bullock |
0a2e55 |
tr("Toggle orientation of the Color Page."));
|
|
shun-iwasawa |
2a343c |
QWidget *toggleOrientationButton =
|
|
shun-iwasawa |
2a343c |
displayToolbar->widgetForAction(m_toggleOrientationAction);
|
|
shun-iwasawa |
2a343c |
toggleOrientationButton->setFixedSize(22, 22);
|
|
shun-iwasawa |
2a343c |
toggleOrientationButton->setFocusPolicy(Qt::NoFocus);
|
|
Jeremy Bullock |
0a2e55 |
displayToolbar->addWidget(toolButton);
|
|
shun-iwasawa |
2a343c |
displayToolbar->setMaximumHeight(22);
|
|
shun-iwasawa |
2a343c |
displayToolbar->setIconSize(QSize(18, 18));
|
|
shun-iwasawa |
2a343c |
|
|
Shinya Kitaoka |
120a6e |
/* ------- layout ------- */
|
|
Jeremy Bullock |
4bf672 |
QGridLayout *mainLayout = new QGridLayout;
|
|
Jeremy Bullock |
915f19 |
mainLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *hLayout = new QHBoxLayout;
|
|
Shinya Kitaoka |
120a6e |
hLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
hLayout->addSpacing(4);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_styleBar);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addStretch();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_tabBarContainer->setLayout(hLayout);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
2a343c |
mainLayout->addWidget(m_tabBarContainer, 0, 0, 1, 2);
|
|
Jeremy Bullock |
4bf672 |
mainLayout->addWidget(m_styleChooser, 1, 0, 1, 2);
|
|
shun-iwasawa |
2a343c |
mainLayout->addWidget(bottomWidget, 2, 0, 1, 2);
|
|
shun-iwasawa |
2a343c |
mainLayout->addWidget(m_toolBar, 3, 0);
|
|
shun-iwasawa |
2a343c |
mainLayout->addWidget(displayToolbar, 3, 1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
2a343c |
mainLayout->setColumnStretch(0, 1);
|
|
shun-iwasawa |
2a343c |
mainLayout->setRowStretch(1, 1);
|
|
Shinya Kitaoka |
120a6e |
setLayout(mainLayout);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* ------- signal-slot connections ------- */
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
shun_iwasawa |
3cc41f |
ret = ret && connect(m_styleBar, SIGNAL(currentChanged(int)), this,
|
|
shun_iwasawa |
3cc41f |
SLOT(setPage(int)));
|
|
shun_iwasawa |
3cc41f |
ret = ret && connect(m_colorParameterSelector, SIGNAL(colorParamChanged()),
|
|
shun_iwasawa |
3cc41f |
this, SLOT(onColorParamChanged()));
|
|
shun_iwasawa |
3cc41f |
ret = ret &&
|
|
shun_iwasawa |
3cc41f |
connect(m_textureStylePage, SIGNAL(styleSelected(const TColorStyle &)),
|
|
shun_iwasawa |
3cc41f |
this, SLOT(selectStyle(const TColorStyle &)));
|
|
shun_iwasawa |
3cc41f |
ret = ret &&
|
|
shun_iwasawa |
3cc41f |
connect(m_specialStylePage, SIGNAL(styleSelected(const TColorStyle &)),
|
|
shun_iwasawa |
3cc41f |
this, SLOT(selectStyle(const TColorStyle &)));
|
|
shun_iwasawa |
3cc41f |
ret = ret &&
|
|
shun_iwasawa |
3cc41f |
connect(m_customStylePage, SIGNAL(styleSelected(const TColorStyle &)),
|
|
shun_iwasawa |
3cc41f |
this, SLOT(selectStyle(const TColorStyle &)));
|
|
shun_iwasawa |
3cc41f |
ret = ret && connect(m_vectorBrushesStylePage,
|
|
shun_iwasawa |
3cc41f |
SIGNAL(styleSelected(const TColorStyle &)), this,
|
|
shun_iwasawa |
3cc41f |
SLOT(selectStyle(const TColorStyle &)));
|
|
shun_iwasawa |
3cc41f |
ret = ret && connect(m_mypaintBrushesStylePage,
|
|
shun_iwasawa |
3cc41f |
SIGNAL(styleSelected(const TColorStyle &)), this,
|
|
shun_iwasawa |
3cc41f |
SLOT(selectStyle(const TColorStyle &)));
|
|
shun_iwasawa |
3cc41f |
ret = ret && connect(m_settingsPage, SIGNAL(paramStyleChanged(bool)), this,
|
|
shun_iwasawa |
3cc41f |
SLOT(onParamStyleChanged(bool)));
|
|
shun_iwasawa |
3cc41f |
ret = ret && connect(m_plainColorPage,
|
|
shun_iwasawa |
3cc41f |
SIGNAL(colorChanged(const ColorModel &, bool)), this,
|
|
shun_iwasawa |
3cc41f |
SLOT(onColorChanged(const ColorModel &, bool)));
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
0a2e55 |
ret = ret && connect(m_wheelAction, SIGNAL(toggled(bool)),
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_wheelFrame, SLOT(setVisible(bool)));
|
|
Jeremy Bullock |
0a2e55 |
ret = ret && connect(m_hsvAction, SIGNAL(toggled(bool)),
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_hsvFrame, SLOT(setVisible(bool)));
|
|
Jeremy Bullock |
0a2e55 |
ret = ret && connect(m_alphaAction, SIGNAL(toggled(bool)),
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_alphaFrame, SLOT(setVisible(bool)));
|
|
Jeremy Bullock |
0a2e55 |
ret = ret && connect(m_rgbAction, SIGNAL(toggled(bool)),
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_rgbFrame, SLOT(setVisible(bool)));
|
|
shun-iwasawa |
2a343c |
ret = ret && connect(m_toggleOrientationAction, SIGNAL(triggered()),
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage, SLOT(toggleOrientation()));
|
|
shun-iwasawa |
2a343c |
ret = ret && connect(m_toggleOrientationAction, SIGNAL(triggered()), this,
|
|
Jeremy Bullock |
0a2e55 |
SLOT(updateOrientationButton()));
|
|
Jeremy Bullock |
0a2e55 |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
/* ------- initial conditions ------- */
|
|
Shinya Kitaoka |
120a6e |
enable(false, false, false);
|
|
Shinya Kitaoka |
120a6e |
// set to the empty page
|
|
Jeremy Bullock |
4bf672 |
m_styleChooser->setCurrentIndex(m_styleChooser->count() - 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
StyleEditor::~StyleEditor() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void StyleEditor::setPaletteHandle(TPaletteHandle* paletteHandle)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
if(m_paletteHandle != paletteHandle)
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle = paletteHandle;
|
|
Shinya Kitaoka |
120a6e |
onStyleSwitched();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QFrame *StyleEditor::createBottomWidget() {
|
|
Shinya Kitaoka |
120a6e |
QFrame *bottomWidget = new QFrame(this);
|
|
Jeremy Bullock |
0a2e55 |
m_autoButton = new QPushButton(tr("Auto"));
|
|
Shinya Kitaoka |
120a6e |
m_oldColor = new DVGui::StyleSample(this, 42, 20);
|
|
Shinya Kitaoka |
120a6e |
m_newColor = new DVGui::StyleSample(this, 42, 20);
|
|
Shinya Kitaoka |
120a6e |
m_applyButton = new QPushButton(tr("Apply"));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bottomWidget->setFrameStyle(QFrame::StyledPanel);
|
|
Shinya Kitaoka |
120a6e |
bottomWidget->setObjectName("bottomWidget");
|
|
Shinya Kitaoka |
120a6e |
bottomWidget->setContentsMargins(0, 0, 0, 0);
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setToolTip(tr("Apply changes to current style"));
|
|
shun_iwasawa |
fd6c3c |
m_applyButton->setDisabled(m_paletteController->isColorAutoApplyEnabled());
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setCheckable(true);
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setToolTip(tr("Automatically update style changes"));
|
|
shun_iwasawa |
fd6c3c |
m_autoButton->setChecked(m_paletteController->isColorAutoApplyEnabled());
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_oldColor->setToolTip(tr("Return To Previous Style"));
|
|
Shinya Kitaoka |
120a6e |
m_oldColor->enableClick(true);
|
|
Shinya Kitaoka |
120a6e |
m_oldColor->setEnable(false);
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setToolTip(tr("Current Style"));
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setEnable(false);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* ------ layout ------ */
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
Jeremy Bullock |
0a2e55 |
mainLayout->setMargin(2);
|
|
Jeremy Bullock |
4bf672 |
mainLayout->setSpacing(1);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *hLayout = new QHBoxLayout;
|
|
Shinya Kitaoka |
120a6e |
hLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
hLayout->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_autoButton);
|
|
Jeremy Bullock |
0a2e55 |
hLayout->addWidget(m_applyButton);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addSpacing(2);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_newColor, 1);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_oldColor, 1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addLayout(hLayout);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
0a2e55 |
// QHBoxLayout *buttonsLayout = new QHBoxLayout;
|
|
Jeremy Bullock |
0a2e55 |
// buttonsLayout->setMargin(0);
|
|
Jeremy Bullock |
0a2e55 |
// buttonsLayout->setSpacing(5);
|
|
Jeremy Bullock |
0a2e55 |
//{ buttonsLayout->addWidget(m_applyButton); }
|
|
Jeremy Bullock |
0a2e55 |
// mainLayout->addLayout(buttonsLayout);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
bottomWidget->setLayout(mainLayout);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* ------ signal-slot connections ------ */
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_applyButton, SIGNAL(clicked()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(applyButtonClicked()));
|
|
shun-iwasawa |
e40777 |
ret = ret && connect(m_autoButton, SIGNAL(toggled(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(autoCheckChanged(bool)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_oldColor, SIGNAL(clicked(const TColorStyle &)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onOldStyleClicked(const TColorStyle &)));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return bottomWidget;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
dfea21 |
QFrame *StyleEditor::createVectorPage() {
|
|
shun-iwasawa |
dfea21 |
QFrame *vectorOutsideFrame = new QFrame(this);
|
|
shun-iwasawa |
dfea21 |
vectorOutsideFrame->setMinimumWidth(50);
|
|
shun-iwasawa |
dfea21 |
|
|
shun-iwasawa |
dfea21 |
QPushButton *specialButton = new QPushButton(tr("Generated"), this);
|
|
shun-iwasawa |
dfea21 |
QPushButton *customButton = new QPushButton(tr("Trail"), this);
|
|
shun-iwasawa |
dfea21 |
QPushButton *vectorBrushButton = new QPushButton(tr("Vector Brush"), this);
|
|
shun-iwasawa |
dfea21 |
|
|
shun-iwasawa |
dfea21 |
specialButton->setCheckable(true);
|
|
shun-iwasawa |
dfea21 |
customButton->setCheckable(true);
|
|
shun-iwasawa |
dfea21 |
vectorBrushButton->setCheckable(true);
|
|
shun-iwasawa |
dfea21 |
specialButton->setChecked(true);
|
|
shun-iwasawa |
dfea21 |
customButton->setChecked(true);
|
|
shun-iwasawa |
dfea21 |
vectorBrushButton->setChecked(true);
|
|
shun-iwasawa |
dfea21 |
|
|
shun-iwasawa |
dfea21 |
/* ------ layout ------ */
|
|
shun-iwasawa |
dfea21 |
QVBoxLayout *vectorOutsideLayout = new QVBoxLayout();
|
|
shun-iwasawa |
dfea21 |
vectorOutsideLayout->setMargin(0);
|
|
shun-iwasawa |
dfea21 |
vectorOutsideLayout->setSpacing(0);
|
|
shun-iwasawa |
dfea21 |
vectorOutsideLayout->setSizeConstraint(QLayout::SetNoConstraint);
|
|
shun-iwasawa |
dfea21 |
{
|
|
shun-iwasawa |
dfea21 |
QHBoxLayout *vectorButtonLayout = new QHBoxLayout();
|
|
shun-iwasawa |
dfea21 |
vectorButtonLayout->setSizeConstraint(QLayout::SetNoConstraint);
|
|
shun-iwasawa |
dfea21 |
{
|
|
shun-iwasawa |
dfea21 |
vectorButtonLayout->addWidget(specialButton);
|
|
shun-iwasawa |
dfea21 |
vectorButtonLayout->addWidget(customButton);
|
|
shun-iwasawa |
dfea21 |
vectorButtonLayout->addWidget(vectorBrushButton);
|
|
shun-iwasawa |
dfea21 |
}
|
|
shun-iwasawa |
dfea21 |
vectorOutsideLayout->addLayout(vectorButtonLayout);
|
|
shun-iwasawa |
dfea21 |
|
|
shun-iwasawa |
dfea21 |
QVBoxLayout *vectorLayout = new QVBoxLayout();
|
|
shun-iwasawa |
dfea21 |
vectorLayout->setMargin(0);
|
|
shun-iwasawa |
dfea21 |
vectorLayout->setSpacing(0);
|
|
shun-iwasawa |
dfea21 |
vectorLayout->setSizeConstraint(QLayout::SetNoConstraint);
|
|
shun-iwasawa |
dfea21 |
{
|
|
shun-iwasawa |
dfea21 |
vectorLayout->addWidget(m_specialStylePage);
|
|
shun-iwasawa |
dfea21 |
vectorLayout->addWidget(m_customStylePage);
|
|
shun-iwasawa |
dfea21 |
vectorLayout->addWidget(m_vectorBrushesStylePage);
|
|
shun-iwasawa |
dfea21 |
}
|
|
shun-iwasawa |
dfea21 |
QFrame *vectorFrame = new QFrame(this);
|
|
shun-iwasawa |
dfea21 |
vectorFrame->setMinimumWidth(50);
|
|
shun-iwasawa |
dfea21 |
vectorFrame->setLayout(vectorLayout);
|
|
shun-iwasawa |
dfea21 |
m_vectorArea = makeChooserPage(vectorFrame);
|
|
shun-iwasawa |
dfea21 |
m_vectorArea->setMinimumWidth(50);
|
|
shun-iwasawa |
dfea21 |
vectorOutsideLayout->addWidget(m_vectorArea);
|
|
shun-iwasawa |
dfea21 |
}
|
|
shun-iwasawa |
dfea21 |
vectorOutsideFrame->setLayout(vectorOutsideLayout);
|
|
shun-iwasawa |
dfea21 |
|
|
shun-iwasawa |
dfea21 |
/* ------ signal-slot connections ------ */
|
|
shun-iwasawa |
dfea21 |
bool ret = true;
|
|
shun-iwasawa |
dfea21 |
ret = ret && connect(specialButton, SIGNAL(toggled(bool)), this,
|
|
shun-iwasawa |
dfea21 |
SLOT(onSpecialButtonToggled(bool)));
|
|
shun-iwasawa |
e40777 |
ret = ret && connect(customButton, SIGNAL(toggled(bool)), this,
|
|
shun-iwasawa |
dfea21 |
SLOT(onCustomButtonToggled(bool)));
|
|
shun-iwasawa |
e40777 |
ret = ret && connect(vectorBrushButton, SIGNAL(toggled(bool)), this,
|
|
shun-iwasawa |
dfea21 |
SLOT(onVectorBrushButtonToggled(bool)));
|
|
shun-iwasawa |
dfea21 |
assert(ret);
|
|
shun-iwasawa |
dfea21 |
return vectorOutsideFrame;
|
|
shun-iwasawa |
dfea21 |
}
|
|
shun-iwasawa |
dfea21 |
|
|
shun-iwasawa |
dfea21 |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
dfea21 |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::updateTabBar() {
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->clearTabBar();
|
|
Shinya Kitaoka |
120a6e |
if (m_enabled && !m_enabledOnlyFirstTab && !m_enabledFirstAndLastTab) {
|
|
Jeremy Bullock |
4bf672 |
m_styleBar->addSimpleTab(tr("Color"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Texture"));
|
|
Jeremy Bullock |
4bf672 |
m_styleBar->addSimpleTab(tr("Vector"));
|
|
Jeremy Bullock |
4bf672 |
m_styleBar->addSimpleTab(tr("Raster"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Settings"));
|
|
Shinya Kitaoka |
120a6e |
} else if (m_enabled && m_enabledOnlyFirstTab && !m_enabledFirstAndLastTab)
|
|
Jeremy Bullock |
4bf672 |
m_styleBar->addSimpleTab(tr("Color"));
|
|
Shinya Kitaoka |
120a6e |
else if (m_enabled && !m_enabledOnlyFirstTab && m_enabledFirstAndLastTab) {
|
|
Jeremy Bullock |
4bf672 |
m_styleBar->addSimpleTab(tr("Color"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Settings"));
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Jeremy Bullock |
4bf672 |
m_styleChooser->setCurrentIndex(m_styleChooser->count() - 1);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_tabBarContainer->layout()->update();
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->setCurrentIndex(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::showEvent(QShowEvent *) {
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setChecked(m_paletteController->isColorAutoApplyEnabled());
|
|
Shinya Kitaoka |
120a6e |
onStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleSwitched()),
|
|
Shinya Kitaoka |
120a6e |
SLOT(onStyleSwitched()));
|
|
shun-iwasawa |
e40777 |
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged(bool)),
|
|
shun_iwasawa |
e553fc |
SLOT(onStyleChanged(bool)));
|
|
shun-iwasawa |
e40777 |
ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onStyleSwitched()));
|
|
Shinya Kitaoka |
120a6e |
if (m_cleanupPaletteHandle)
|
|
shun_iwasawa |
e553fc |
ret =
|
|
shun_iwasawa |
e553fc |
ret && connect(m_cleanupPaletteHandle, SIGNAL(colorStyleChanged(bool)),
|
|
shun_iwasawa |
e553fc |
SLOT(onCleanupStyleChanged(bool)));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_paletteController, SIGNAL(colorAutoApplyEnabled(bool)),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(enableColorAutoApply(bool)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_paletteController,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(colorSampleChanged(const TPixel32 &)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setColorSample(const TPixel32 &)));
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_wheelFrame->setVisible(m_wheelAction->isChecked());
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_hsvFrame->setVisible(m_hsvAction->isChecked());
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_alphaFrame->setVisible(m_alphaAction->isChecked());
|
|
Jeremy Bullock |
0a2e55 |
m_plainColorPage->m_rgbFrame->setVisible(m_rgbAction->isChecked());
|
|
Jeremy Bullock |
0a2e55 |
updateOrientationButton();
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::hideEvent(QHideEvent *) {
|
|
shun-iwasawa |
11adda |
disconnect(m_paletteHandle, 0, this, 0);
|
|
shun-iwasawa |
11adda |
if (m_cleanupPaletteHandle) disconnect(m_cleanupPaletteHandle, 0, this, 0);
|
|
shun-iwasawa |
11adda |
disconnect(m_paletteController, 0, this, 0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
0a2e55 |
void StyleEditor::updateOrientationButton() {
|
|
Jeremy Bullock |
0a2e55 |
if (m_plainColorPage->getIsVertical()) {
|
|
shun-iwasawa |
2a343c |
m_toggleOrientationAction->setIcon(QIcon(":Resources/orientation_h.svg"));
|
|
Jeremy Bullock |
0a2e55 |
} else {
|
|
shun-iwasawa |
2a343c |
m_toggleOrientationAction->setIcon(QIcon(":Resources/orientation_v.svg"));
|
|
Jeremy Bullock |
0a2e55 |
}
|
|
Jeremy Bullock |
0a2e55 |
}
|
|
Jeremy Bullock |
0a2e55 |
|
|
Jeremy Bullock |
0a2e55 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
0a2e55 |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::onStyleSwitched() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!palette) {
|
|
Shinya Kitaoka |
120a6e |
// set the current page to empty
|
|
Jeremy Bullock |
4bf672 |
m_styleChooser->setCurrentIndex(m_styleChooser->count() - 1);
|
|
Shinya Kitaoka |
120a6e |
enable(false);
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector->clear();
|
|
Shinya Kitaoka |
120a6e |
m_oldStyle = TColorStyleP();
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle = TColorStyleP();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
0a2e55 |
m_parent->setWindowTitle(tr("No Style Selected"));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
setEditedStyleToStyle(palette->getStyle(styleIndex));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool isStyleNull = setStyle(m_editedStyle.getPointer());
|
|
Shinya Kitaoka |
120a6e |
bool isColorInField = palette->getPaletteName() == L"EmptyColorFieldPalette";
|
|
Shinya Kitaoka |
120a6e |
bool isValidIndex = styleIndex > 0 || isColorInField;
|
|
Shinya Kitaoka |
120a6e |
bool isCleanUpPalette = palette->isCleanupPalette();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ------ update the status text ------ */
|
|
Shinya Kitaoka |
120a6e |
if (!isStyleNull && isValidIndex) {
|
|
Shinya Kitaoka |
120a6e |
QString statusText;
|
|
Shinya Kitaoka |
120a6e |
// palette type
|
|
Shinya Kitaoka |
120a6e |
if (isCleanUpPalette)
|
|
Yu Chen |
da5534 |
statusText = tr("[CLEANUP] ");
|
|
Shinya Kitaoka |
120a6e |
else if (palette->getGlobalName() != L"")
|
|
Yu Chen |
da5534 |
statusText = tr("[STUDIO] ");
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Yu Chen |
da5534 |
statusText = tr("[LEVEL] ");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// palette name
|
|
shun-iwasawa |
e87e08 |
statusText += tr("Palette") + " : " +
|
|
shun-iwasawa |
e87e08 |
QString::fromStdWString(palette->getPaletteName());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// style name
|
|
shun_iwasawa |
9cbd0e |
statusText += QString::fromStdWString(L" | #");
|
|
Shinya Kitaoka |
120a6e |
statusText += QString::number(styleIndex);
|
|
Shinya Kitaoka |
120a6e |
statusText += QString::fromStdWString(L" : " + m_editedStyle->getName());
|
|
shun-iwasawa |
dd780b |
TPoint pickedPos = m_editedStyle->getPickedPosition().pos;
|
|
shun_iwasawa |
9cbd0e |
if (pickedPos != TPoint())
|
|
shun_iwasawa |
9cbd0e |
statusText +=
|
|
shun_iwasawa |
9cbd0e |
QString(" (Picked from %1,%2)").arg(pickedPos.x).arg(pickedPos.y);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
0a2e55 |
m_parent->setWindowTitle(statusText);
|
|
Jeremy Bullock |
0a2e55 |
} else {
|
|
Jeremy Bullock |
0a2e55 |
m_parent->setWindowTitle(tr("Style Editor - No Valid Style Selected"));
|
|
Jeremy Bullock |
0a2e55 |
}
|
|
Shinya Kitaoka |
120a6e |
enable(!isStyleNull && isValidIndex, isColorInField, isCleanUpPalette);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
e553fc |
void StyleEditor::onStyleChanged(bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= styleIndex && styleIndex < palette->getStyleCount());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setEditedStyleToStyle(palette->getStyle(styleIndex));
|
|
shun_iwasawa |
e553fc |
if (!isDragging) {
|
|
shun_iwasawa |
e553fc |
setOldStyleToStyle(
|
|
shun_iwasawa |
e553fc |
m_editedStyle
|
|
shun_iwasawa |
e553fc |
.getPointer()); // This line is needed for proper undo behavior
|
|
shun_iwasawa |
e553fc |
}
|
|
Shinya Kitaoka |
120a6e |
m_plainColorPage->setColor(*m_editedStyle, getColorParam());
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector->setStyle(*m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
m_settingsPage->setStyle(m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setStyle(*m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
m_oldColor->setStyle(
|
|
Shinya Kitaoka |
120a6e |
*m_oldStyle); // This line is needed for proper undo behavior
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
e553fc |
void StyleEditor::onCleanupStyleChanged(bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_cleanupPaletteHandle) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
e553fc |
onStyleChanged(isDragging);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
// TOGLIERE
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::setRootPath(const TFilePath &rootPath) {
|
|
Shinya Kitaoka |
120a6e |
m_textureStylePage->setRootPath(rootPath);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::copyEditedStyleToPalette(bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
assert(palette);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= styleIndex && styleIndex < palette->getStyleCount());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!(*m_oldStyle == *m_editedStyle) &&
|
|
Shinya Kitaoka |
120a6e |
(!isDragging || m_paletteController->isColorAutoApplyEnabled()) &&
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getGlobalName() != L"" &&
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getOriginalName() != L"") {
|
|
Shinya Kitaoka |
120a6e |
// If the adited style is linked to the studio palette, then activate the
|
|
Shinya Kitaoka |
120a6e |
// edited flag
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setIsEditedFlag(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
e40777 |
palette->setStyle(styleIndex,
|
|
shun-iwasawa |
e40777 |
m_editedStyle->clone()); // Must be done *before* setting
|
|
shun-iwasawa |
e40777 |
// the eventual palette keyframe
|
|
Shinya Kitaoka |
120a6e |
if (!isDragging) {
|
|
Shinya Kitaoka |
120a6e |
if (!(*m_oldStyle == *m_editedStyle)) {
|
|
Shinya Kitaoka |
120a6e |
// do not register undo if the edited color is special one (e.g. changing
|
|
Shinya Kitaoka |
120a6e |
// the ColorField in the fx settings)
|
|
Shinya Kitaoka |
120a6e |
if (palette->getPaletteName() != L"EmptyColorFieldPalette")
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new UndoPaletteChange(
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle, styleIndex, *m_oldStyle, *m_editedStyle));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
setOldStyleToStyle(m_editedStyle.getPointer());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// In case the frame is a keyframe, update it
|
|
Shinya Kitaoka |
120a6e |
if (palette->isKeyframe(styleIndex, palette->getFrame())) // here
|
|
Shinya Kitaoka |
120a6e |
palette->setKeyframe(styleIndex, palette->getFrame()); //
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(isDragging);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::onColorChanged(const ColorModel &color, bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
if (styleIndex < 0 || styleIndex > palette->getStyleCount()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setEditedStyleToStyle(palette->getStyle(styleIndex)); // CLONES the argument
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_editedStyle) // Should be styleIndex's style at this point
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TPixel tColor = color.getTPixel();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_editedStyle->hasMainColor()) {
|
|
Shinya Kitaoka |
120a6e |
int index = getColorParam(), count = m_editedStyle->getColorParamCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (0 <= index && index < count)
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setColorParamValue(index, tColor);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setMainColor(tColor);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->invalidateIcon();
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
// The argument has NO (main) COLOR. Since color data is being updated, a
|
|
Shinya Kitaoka |
120a6e |
// 'fake'
|
|
Shinya Kitaoka |
120a6e |
// solid style will be created and operated on.
|
|
Shinya Kitaoka |
120a6e |
TSolidColorStyle *style = new TSolidColorStyle(tColor);
|
|
Shinya Kitaoka |
120a6e |
style->assignNames(m_editedStyle.getPointer());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setEditedStyleToStyle(style); // CLONES the argument
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
delete style;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setStyle(*m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector->setStyle(*m_editedStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_autoButton->isChecked()) {
|
|
Shinya Kitaoka |
120a6e |
copyEditedStyleToPalette(isDragging);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::enable(bool enabled, bool enabledOnlyFirstTab,
|
|
Shinya Kitaoka |
120a6e |
bool enabledFirstAndLastTab) {
|
|
Shinya Kitaoka |
120a6e |
if (m_enabled != enabled || m_enabledOnlyFirstTab != enabledOnlyFirstTab ||
|
|
Shinya Kitaoka |
120a6e |
m_enabledFirstAndLastTab != enabledFirstAndLastTab) {
|
|
Shinya Kitaoka |
120a6e |
m_enabled = enabled;
|
|
Shinya Kitaoka |
120a6e |
m_enabledOnlyFirstTab = enabledOnlyFirstTab;
|
|
Shinya Kitaoka |
120a6e |
m_enabledFirstAndLastTab = enabledFirstAndLastTab;
|
|
Shinya Kitaoka |
120a6e |
updateTabBar();
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setEnabled(enabled);
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setDisabled(!enabled || m_autoButton->isChecked());
|
|
Shinya Kitaoka |
120a6e |
m_oldColor->setEnable(enabled);
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setEnable(enabled);
|
|
Shinya Kitaoka |
120a6e |
if (enabled == false) {
|
|
Shinya Kitaoka |
120a6e |
m_oldColor->setColor(TPixel32::Transparent);
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setColor(TPixel32::Transparent);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// lock button behavior
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (palette && enabled) {
|
|
Shinya Kitaoka |
120a6e |
// when the palette is locked
|
|
Shinya Kitaoka |
120a6e |
if (palette->isLocked()) {
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setEnabled(false);
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setChecked(false);
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setEnabled(false);
|
|
Shinya Kitaoka |
120a6e |
} else // when the palette is unlocked
|
|
Shinya Kitaoka |
120a6e |
{
|
|
shun_iwasawa |
fd6c3c |
m_applyButton->setDisabled(m_autoButton->isChecked());
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setEnabled(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::onOldStyleClicked(const TColorStyle &) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_enabled) return;
|
|
Shinya Kitaoka |
120a6e |
selectStyle(*(m_oldColor->getStyle()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::setPage(int index) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_enabledFirstAndLastTab) {
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->setCurrentIndex(index);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Se sono nel caso first and last page enable e index == 1 la pagina che
|
|
Shinya Kitaoka |
120a6e |
// voglio settare e' l'ultima!
|
|
Shinya Kitaoka |
120a6e |
if (index == 1)
|
|
Shinya Kitaoka |
120a6e |
index = m_styleChooser->count() -
|
|
Shinya Kitaoka |
120a6e |
2; // 2 perche' alla fine c'e' una pagina vuota
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->setCurrentIndex(index);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::applyButtonClicked() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || styleIndex < 0 || styleIndex > palette->getStyleCount())
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
copyEditedStyleToPalette(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::autoCheckChanged(bool value) {
|
|
shun_iwasawa |
fd6c3c |
m_paletteController->enableColorAutoApply(value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_enabled) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
fd6c3c |
m_applyButton->setDisabled(value);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::enableColorAutoApply(bool enabled) {
|
|
Shinya Kitaoka |
120a6e |
if (m_autoButton->isChecked() != enabled) {
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setChecked(enabled);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::setColorSample(const TPixel32 &color) {
|
|
Shinya Kitaoka |
120a6e |
// m_colorParameterSelector->setColor(*style);
|
|
Shinya Kitaoka |
120a6e |
ColorModel cm;
|
|
Shinya Kitaoka |
120a6e |
cm.setTPixel(color);
|
|
Shinya Kitaoka |
120a6e |
onColorChanged(cm, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool StyleEditor::setStyle(TColorStyle *currentStyle) {
|
|
Shinya Kitaoka |
120a6e |
assert(currentStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool isStyleNull = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QString gname = QString::fromStdWString(currentStyle->getGlobalName());
|
|
Shinya Kitaoka |
120a6e |
// if(!gname.isEmpty() && gname == "ColorFieldSimpleColor")
|
|
Shinya Kitaoka |
120a6e |
// isStyleNull = true;
|
|
Shinya Kitaoka |
120a6e |
// else
|
|
Shinya Kitaoka |
120a6e |
if (!gname.isEmpty() && gname[0] != L'-') {
|
|
Shinya Kitaoka |
120a6e |
currentStyle = 0;
|
|
Shinya Kitaoka |
120a6e |
isStyleNull = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (currentStyle) {
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector->setStyle(*currentStyle);
|
|
Shinya Kitaoka |
120a6e |
m_plainColorPage->setColor(*currentStyle, getColorParam());
|
|
Shinya Kitaoka |
120a6e |
m_oldColor->setStyle(*currentStyle);
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setStyle(*currentStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setOldStyleToStyle(currentStyle);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Va fatto anche se non c'e' lo style perche' svuota la pagina
|
|
Shinya Kitaoka |
120a6e |
m_settingsPage->setStyle(m_editedStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return isStyleNull;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::setEditedStyleToStyle(const TColorStyle *style) {
|
|
Shinya Kitaoka |
120a6e |
if (style == m_editedStyle.getPointer()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle = TColorStyleP(style->clone());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::setOldStyleToStyle(const TColorStyle *style) {
|
|
Shinya Kitaoka |
120a6e |
if (style == m_oldStyle.getPointer()) return;
|
|
Shinya Kitaoka |
120a6e |
m_oldStyle = TColorStyleP(style->clone());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::selectStyle(const TColorStyle &newStyle) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = m_paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = m_paletteHandle->getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
if (styleIndex < 0 || palette->getStyleCount() <= styleIndex) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Register the new previous/edited style pairs
|
|
Shinya Kitaoka |
120a6e |
setOldStyleToStyle(palette->getStyle(styleIndex));
|
|
Shinya Kitaoka |
120a6e |
setEditedStyleToStyle(&newStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->assignNames(
|
|
Shinya Kitaoka |
120a6e |
m_oldStyle.getPointer()); // Copy original name stored in the palette
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// For convenience's sake, copy the main color from the old color, if both
|
|
Shinya Kitaoka |
120a6e |
// have one
|
|
Shinya Kitaoka |
120a6e |
if (m_oldStyle && m_oldStyle->hasMainColor() && m_editedStyle &&
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->hasMainColor())
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setMainColor(m_oldStyle->getMainColor());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_autoButton->isChecked()) {
|
|
Shinya Kitaoka |
120a6e |
// If the adited style is linked to the studio palette, then activate the
|
|
Shinya Kitaoka |
120a6e |
// edited flag
|
|
Shinya Kitaoka |
120a6e |
if (m_editedStyle->getGlobalName() != L"" &&
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->getOriginalName() != L"")
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->setIsEditedFlag(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Apply new style, if required
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new UndoPaletteChange(
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle, styleIndex, *m_oldStyle, *m_editedStyle));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(styleIndex, m_editedStyle->clone());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false);
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Update editor widgets
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setStyle(*m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
m_plainColorPage->setColor(*m_editedStyle, getColorParam());
|
|
Shinya Kitaoka |
120a6e |
m_colorParameterSelector->setStyle(*m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
m_settingsPage->setStyle(m_editedStyle);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::onColorParamChanged() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
if (styleIndex < 0 || palette->getStyleCount() <= styleIndex) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->setStyleParamIndex(getColorParam());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (TColorStyle *currentStyle = palette->getStyle(styleIndex)) {
|
|
Shinya Kitaoka |
120a6e |
setEditedStyleToStyle(currentStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_plainColorPage->setColor(*m_editedStyle, getColorParam());
|
|
Shinya Kitaoka |
120a6e |
m_settingsPage->setStyle(m_editedStyle);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::onParamStyleChanged(bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int styleIndex = getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
if (styleIndex < 0 || styleIndex > palette->getStyleCount()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_autoButton->isChecked()) copyEditedStyleToPalette(isDragging);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->invalidateIcon(); // Refresh the new color icon
|
|
Shinya Kitaoka |
120a6e |
m_newColor->setStyle(*m_editedStyle); //
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
void StyleEditor::onSpecialButtonToggled(bool on) {
|
|
Jeremy Bullock |
4bf672 |
m_specialStylePage->setVisible(on);
|
|
Jeremy Bullock |
4bf672 |
m_vectorArea->widget()->resize(m_vectorArea->widget()->sizeHint());
|
|
Jeremy Bullock |
4bf672 |
qApp->processEvents();
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
void StyleEditor::onCustomButtonToggled(bool on) {
|
|
Jeremy Bullock |
4bf672 |
m_customStylePage->setVisible(on);
|
|
Jeremy Bullock |
4bf672 |
m_vectorArea->widget()->resize(m_vectorArea->widget()->sizeHint());
|
|
Jeremy Bullock |
4bf672 |
qApp->processEvents();
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
void StyleEditor::onVectorBrushButtonToggled(bool on) {
|
|
Jeremy Bullock |
4bf672 |
m_vectorBrushesStylePage->setVisible(on);
|
|
Jeremy Bullock |
4bf672 |
m_vectorArea->widget()->resize(m_vectorArea->widget()->sizeHint());
|
|
Jeremy Bullock |
4bf672 |
qApp->processEvents();
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
//-----------------------------------------------------------------------------
|
|
Jeremy Bullock |
4bf672 |
|
|
Jeremy Bullock |
4bf672 |
void StyleEditor::save(QSettings &settings) const {
|
|
Jeremy Bullock |
4bf672 |
settings.setValue("isVertical", m_plainColorPage->getIsVertical());
|
|
Jeremy Bullock |
0a2e55 |
int visibleParts = 0;
|
|
Jeremy Bullock |
0a2e55 |
if (m_wheelAction->isChecked()) visibleParts |= 0x01;
|
|
Jeremy Bullock |
0a2e55 |
if (m_hsvAction->isChecked()) visibleParts |= 0x02;
|
|
Jeremy Bullock |
0a2e55 |
if (m_alphaAction->isChecked()) visibleParts |= 0x04;
|
|
Jeremy Bullock |
0a2e55 |
if (m_rgbAction->isChecked()) visibleParts |= 0x08;
|
|
Jeremy Bullock |
0a2e55 |
settings.setValue("visibleParts", visibleParts);
|
|
Jeremy Bullock |
4bf672 |
settings.setValue("splitterState", m_plainColorPage->getSplitterState());
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
void StyleEditor::load(QSettings &settings) {
|
|
Jeremy Bullock |
4bf672 |
QVariant isVertical = settings.value("isVertical");
|
|
Jeremy Bullock |
4bf672 |
if (isVertical.canConvert(QVariant::Bool)) {
|
|
Jeremy Bullock |
4bf672 |
m_colorPageIsVertical = isVertical.toBool();
|
|
Jeremy Bullock |
4bf672 |
m_plainColorPage->setIsVertical(m_colorPageIsVertical);
|
|
Jeremy Bullock |
4bf672 |
}
|
|
Jeremy Bullock |
4bf672 |
QVariant visibleParts = settings.value("visibleParts");
|
|
Jeremy Bullock |
0a2e55 |
if (visibleParts.canConvert(QVariant::Int)) {
|
|
Jeremy Bullock |
0a2e55 |
int visiblePartsInt = visibleParts.toInt();
|
|
Jeremy Bullock |
0a2e55 |
|
|
Jeremy Bullock |
0a2e55 |
if (visiblePartsInt & 0x01)
|
|
Jeremy Bullock |
0a2e55 |
m_wheelAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
else
|
|
Jeremy Bullock |
0a2e55 |
m_wheelAction->setChecked(false);
|
|
Jeremy Bullock |
0a2e55 |
if (visiblePartsInt & 0x02)
|
|
Jeremy Bullock |
0a2e55 |
m_hsvAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
else
|
|
Jeremy Bullock |
0a2e55 |
m_hsvAction->setChecked(false);
|
|
Jeremy Bullock |
0a2e55 |
if (visiblePartsInt & 0x04)
|
|
Jeremy Bullock |
0a2e55 |
m_alphaAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
else
|
|
Jeremy Bullock |
0a2e55 |
m_alphaAction->setChecked(false);
|
|
Jeremy Bullock |
0a2e55 |
if (visiblePartsInt & 0x08)
|
|
Jeremy Bullock |
0a2e55 |
m_rgbAction->setChecked(true);
|
|
Jeremy Bullock |
0a2e55 |
else
|
|
Jeremy Bullock |
0a2e55 |
m_rgbAction->setChecked(false);
|
|
Jeremy Bullock |
0a2e55 |
}
|
|
Jeremy Bullock |
4bf672 |
QVariant splitterState = settings.value("splitterState");
|
|
Jeremy Bullock |
4bf672 |
if (splitterState.canConvert(QVariant::ByteArray))
|
|
Jeremy Bullock |
4bf672 |
m_plainColorPage->setSplitterState(splitterState.toByteArray());
|
|
Jeremy Bullock |
4bf672 |
}
|