|
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"
|
|
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
|
|
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>
|
|
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;
|
|
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;
|
|
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)
|
|
Shinya Kitaoka |
120a6e |
: QOpenGLWidget(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;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// iwsw commented out temporarily
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled() &&
|
|
Shinya Kitaoka |
120a6e |
Ghibli3DLutUtil::m_isValid)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil = new Ghibli3DLutUtil();
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil->setInvert();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
HexagonalColorWheel::~HexagonalColorWheel() {
|
|
Shinya Kitaoka |
120a6e |
// iwsw commented out temporarily
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(m_ghibli3DLutUtil)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil->onEnd();
|
|
Shinya Kitaoka |
120a6e |
delete m_ghibli3DLutUtil;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::initializeGL() {
|
|
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 |
// iwsw commented out temporarily
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled() &&
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil)
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil->onInit();
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HexagonalColorWheel::resizeGL(int width, int height) {
|
|
Shinya Kitaoka |
120a6e |
float d = (width - 5.0f) / 2.5f;
|
|
Shinya Kitaoka |
120a6e |
bool isHorizontallyLong = ((d * 1.732f) < height) ? false : true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (isHorizontallyLong) {
|
|
Shinya Kitaoka |
120a6e |
m_triEdgeLen = (float)height / 1.732f;
|
|
Shinya Kitaoka |
120a6e |
m_triHeight = (float)height / 2.0f;
|
|
Shinya Kitaoka |
120a6e |
m_wheelPosition.setX(((float)width - (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);
|
|
Shinya Kitaoka |
120a6e |
m_wheelPosition.setY(((float)height - (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
|
|
Shinya Kitaoka |
120a6e |
glViewport(0, 0, width, height);
|
|
Shinya Kitaoka |
120a6e |
glMatrixMode(GL_PROJECTION);
|
|
Shinya Kitaoka |
120a6e |
glLoadIdentity();
|
|
Shinya Kitaoka |
120a6e |
glOrtho(0.0, (GLdouble)width, (GLdouble)height, 0.0, 1.0, -1.0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// iwsw commented out temporarily
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled() &&
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil)
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil->onResize(width,height);
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
// iwsw commented out temporarily
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled() &&
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil)
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil->startDraw();
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
// iwsw commented out temporarily
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled() &&
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil)
|
|
Shinya Kitaoka |
120a6e |
m_ghibli3DLutUtil->endDraw();
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
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).
|
|
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);
|
|
Shinya Kitaoka |
120a6e |
if (wheelPolygon.toPolygon().containsPoint(event->pos(), Qt::OddEvenFill)) {
|
|
Shinya Kitaoka |
120a6e |
m_currentWheel = leftWheel;
|
|
Shinya Kitaoka |
120a6e |
clickLeftWheel(event->pos());
|
|
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);
|
|
Shinya Kitaoka |
120a6e |
if (wheelPolygon.toPolygon().containsPoint(event->pos(), Qt::OddEvenFill)) {
|
|
Shinya Kitaoka |
120a6e |
m_currentWheel = rightTriangle;
|
|
Shinya Kitaoka |
120a6e |
clickRightTriangle(event->pos());
|
|
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:
|
|
Shinya Kitaoka |
120a6e |
clickLeftWheel(event->pos());
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case rightTriangle:
|
|
Shinya Kitaoka |
120a6e |
clickRightTriangle(event->pos());
|
|
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
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
static const char *names[] = {"R", "G", "B", "M", "H", "S", "V"};
|
|
Shinya Kitaoka |
120a6e |
assert(0 <= (int)m_channel && (int)m_channel < 7);
|
|
Shinya Kitaoka |
120a6e |
QString text = names[(int)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 |
|
|
Shinya Kitaoka |
120a6e |
QPushButton *wheelShowButton = new QPushButton(tr("Wheel"), this);
|
|
Shinya Kitaoka |
120a6e |
QPushButton *hsvShowButton = new QPushButton(tr("HSV"), this);
|
|
Shinya Kitaoka |
120a6e |
QPushButton *matteShowButton = new QPushButton(tr("Matte"), this);
|
|
Shinya Kitaoka |
120a6e |
QPushButton *rgbShowButton = new QPushButton(tr("RGB"), this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QFrame *wheelFrame = new QFrame(this);
|
|
Shinya Kitaoka |
120a6e |
QFrame *hsvFrame = new QFrame(this);
|
|
Shinya Kitaoka |
120a6e |
QFrame *matteFrame = new QFrame(this);
|
|
Shinya Kitaoka |
120a6e |
QFrame *rgbFrame = new QFrame(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QFrame *slidersContainer = new QFrame(this);
|
|
Shinya Kitaoka |
120a6e |
QSplitter *vSplitter = new QSplitter(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//プロパティの設定
|
|
Shinya Kitaoka |
120a6e |
// channelButtonGroup->setExclusive(true);
|
|
Shinya Kitaoka |
120a6e |
wheelShowButton->setCheckable(true);
|
|
Shinya Kitaoka |
120a6e |
hsvShowButton->setCheckable(true);
|
|
Shinya Kitaoka |
120a6e |
matteShowButton->setCheckable(true);
|
|
Shinya Kitaoka |
120a6e |
rgbShowButton->setCheckable(true);
|
|
Shinya Kitaoka |
120a6e |
wheelShowButton->setMinimumWidth(30);
|
|
Shinya Kitaoka |
120a6e |
hsvShowButton->setMinimumWidth(30);
|
|
Shinya Kitaoka |
120a6e |
matteShowButton->setMinimumWidth(30);
|
|
Shinya Kitaoka |
120a6e |
rgbShowButton->setMinimumWidth(30);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
wheelFrame->setObjectName("PlainColorPageParts");
|
|
Shinya Kitaoka |
120a6e |
hsvFrame->setObjectName("PlainColorPageParts");
|
|
Shinya Kitaoka |
120a6e |
matteFrame->setObjectName("PlainColorPageParts");
|
|
Shinya Kitaoka |
120a6e |
rgbFrame->setObjectName("PlainColorPageParts");
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
wheelShowButton->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
wheelShowButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
hsvShowButton->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
hsvShowButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
matteShowButton->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
matteShowButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
rgbShowButton->setChecked(true);
|
|
Shinya Kitaoka |
120a6e |
rgbShowButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
vSplitter->setOrientation(Qt::Vertical);
|
|
Shinya Kitaoka |
120a6e |
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 *showButtonLayout = new QHBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
showButtonLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
showButtonLayout->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
showButtonLayout->addWidget(wheelShowButton, 1);
|
|
Shinya Kitaoka |
120a6e |
showButtonLayout->addWidget(hsvShowButton, 1);
|
|
Shinya Kitaoka |
120a6e |
showButtonLayout->addWidget(matteShowButton, 1);
|
|
Shinya Kitaoka |
120a6e |
showButtonLayout->addWidget(rgbShowButton, 1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addLayout(showButtonLayout);
|
|
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); }
|
|
Shinya Kitaoka |
120a6e |
wheelFrame->setLayout(wheelLayout);
|
|
Shinya Kitaoka |
120a6e |
vSplitter->addWidget(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 |
}
|
|
Shinya Kitaoka |
120a6e |
hsvFrame->setLayout(hsvLayout);
|
|
Shinya Kitaoka |
120a6e |
slidersLayout->addWidget(hsvFrame, 3);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *matteLayout = new QVBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
matteLayout->setMargin(4);
|
|
Shinya Kitaoka |
120a6e |
matteLayout->setSpacing(4);
|
|
Shinya Kitaoka |
120a6e |
{ matteLayout->addWidget(m_channelControls[eAlpha]); }
|
|
Shinya Kitaoka |
120a6e |
matteFrame->setLayout(matteLayout);
|
|
Shinya Kitaoka |
120a6e |
slidersLayout->addWidget(matteFrame, 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 |
}
|
|
Shinya Kitaoka |
120a6e |
rgbFrame->setLayout(rgbLayout);
|
|
Shinya Kitaoka |
120a6e |
slidersLayout->addWidget(rgbFrame, 3);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
slidersContainer->setLayout(slidersLayout);
|
|
Shinya Kitaoka |
120a6e |
vSplitter->addWidget(slidersContainer);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(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;
|
|
Shinya Kitaoka |
120a6e |
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)));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Show/Hideトグルボタン
|
|
Shinya Kitaoka |
120a6e |
connect(wheelShowButton, SIGNAL(toggled(bool)), wheelFrame,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setVisible(bool)));
|
|
Shinya Kitaoka |
120a6e |
connect(hsvShowButton, SIGNAL(toggled(bool)), hsvFrame,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setVisible(bool)));
|
|
Shinya Kitaoka |
120a6e |
connect(matteShowButton, SIGNAL(toggled(bool)), matteFrame,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setVisible(bool)));
|
|
Shinya Kitaoka |
120a6e |
connect(rgbShowButton, SIGNAL(toggled(bool)), rgbFrame,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setVisible(bool)));
|
|
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 |
//-----------------------------------------------------------------------------
|
|
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;
|
|
Shinya Kitaoka |
120a6e |
setMinimumSize(5 * 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);
|
|
Shinya Kitaoka |
120a6e |
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
|
|
Shinya Kitaoka |
120a6e |
QToolTip::showText(he->globalPos(), tr("Plain color"));
|
|
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;
|
|
Shinya Kitaoka |
120a6e |
QToolTip::showText(helpEvent->globalPos(),
|
|
Shinya Kitaoka |
120a6e |
toolTip != QString() ? toolTip : "Custom Texture");
|
|
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 |
//*****************************************************************************
|
|
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 || // ??
|
|
Shinya Kitaoka |
120a6e |
tagId == 3000 // vector brush
|
|
Shinya Kitaoka |
120a6e |
)
|
|
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)
|
|
Shinya Kitaoka |
120a6e |
toolTip = tr("Plain color");
|
|
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);
|
|
Shinya Kitaoka |
120a6e |
paramsContainer->setLayout(paramsContainerLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Add a vertical layout to store the "autofill" checkbox widgets
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_autopaintToggleBox = new QWidget(this);
|
|
Shinya Kitaoka |
120a6e |
// box->setFixedHeight(22);
|
|
Shinya Kitaoka |
120a6e |
paramsContainerLayout->addWidget(m_autopaintToggleBox);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *hLayout = new QHBoxLayout;
|
|
Shinya Kitaoka |
120a6e |
m_autopaintToggleBox->setLayout(hLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
hLayout->setSpacing(5);
|
|
Shinya Kitaoka |
120a6e |
hLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
hLayout->addSpacing(98);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_autoFillCheckBox = new QCheckBox;
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(m_autoFillCheckBox);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QLabel *label =
|
|
Shinya Kitaoka |
120a6e |
new QLabel(StyleEditorGUI::SettingsPage::tr("Autopaint for Lines"));
|
|
Shinya Kitaoka |
120a6e |
hLayout->addWidget(label);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
hLayout->addStretch();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ret = connect(m_autoFillCheckBox, SIGNAL(stateChanged(int)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onAutofillChanged()));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Prepare the style parameters layout
|
|
Shinya Kitaoka |
120a6e |
m_paramsLayout = new QGridLayout;
|
|
Shinya Kitaoka |
120a6e |
paramsContainerLayout->addLayout(m_paramsLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
paramsContainerLayout->addStretch();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SettingsPage::enableAutopaintToggle(bool enabled) {
|
|
Shinya Kitaoka |
120a6e |
m_autopaintToggleBox->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 |
|
|
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) {
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
void SettingsPage::onValueChanged(bool isDragging) {
|
|
Shinya Kitaoka |
120a6e |
struct Locals {
|
|
Shinya Kitaoka |
120a6e |
SettingsPage *m_this;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int paramIndex(const QWidget *widget) {
|
|
Shinya Kitaoka |
120a6e |
int p, pCount = m_this->m_paramsLayout->rowCount();
|
|
Shinya Kitaoka |
120a6e |
for (p = 0; p != pCount; ++p)
|
|
Shinya Kitaoka |
120a6e |
if (m_this->m_paramsLayout->itemAtPosition(p, 1)->widget() == widget)
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return p;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
} locals = {this};
|
|
Shinya Kitaoka |
120a6e |
|
|
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>
|
|
Shinya Kitaoka |
120a6e |
int p = locals.paramIndex(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)
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
m_plainColorPage = new PlainColorPage(0);
|
|
Shinya Kitaoka |
120a6e |
m_textureStylePage = new TextureStyleChooserPage(0);
|
|
Shinya Kitaoka |
120a6e |
m_specialStylePage = new SpecialStyleChooserPage(0);
|
|
Shinya Kitaoka |
120a6e |
m_customStylePage = new CustomStyleChooserPage(0);
|
|
Shinya Kitaoka |
120a6e |
m_vectorBrushesStylePage = new VectorBrushStyleChooserPage(0);
|
|
Shinya Kitaoka |
120a6e |
m_settingsPage = new SettingsPage(0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QWidget *emptyPage = new StyleEditorPage(0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_statusLabel = new QLabel("", this);
|
|
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
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *plainArea = makeChooserPageWithoutScrollBar(m_plainColorPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *textureArea = makeChooserPage(m_textureStylePage);
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *specialArea = makeChooserPage(m_specialStylePage);
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *customArea = makeChooserPage(m_customStylePage);
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *vectorBrushesArea = makeChooserPage(m_vectorBrushesStylePage);
|
|
Shinya Kitaoka |
120a6e |
QScrollArea *settingsArea = makeChooserPageWithoutScrollBar(m_settingsPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser = new QStackedWidget(this);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(plainArea);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(textureArea);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(specialArea);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(customArea);
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->addWidget(vectorBrushesArea);
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
/* ------- layout ------- */
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setMargin(1);
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(m_tabBarContainer, 0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(m_styleChooser, 1);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(bottomWidget, 0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(m_statusLabel, 0);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->addWidget(m_toolBar, 0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
setLayout(mainLayout);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* ------- signal-slot connections ------- */
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool ret = true;
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_styleBar, SIGNAL(currentChanged(int)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setPage(int)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_colorParameterSelector, SIGNAL(colorParamChanged()),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(onColorParamChanged()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret &&
|
|
Shinya Kitaoka |
120a6e |
connect(m_textureStylePage, SIGNAL(styleSelected(const TColorStyle &)),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(selectStyle(const TColorStyle &)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret &&
|
|
Shinya Kitaoka |
120a6e |
connect(m_specialStylePage, SIGNAL(styleSelected(const TColorStyle &)),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(selectStyle(const TColorStyle &)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret &&
|
|
Shinya Kitaoka |
120a6e |
connect(m_customStylePage, SIGNAL(styleSelected(const TColorStyle &)),
|
|
Shinya Kitaoka |
120a6e |
this, SLOT(selectStyle(const TColorStyle &)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_vectorBrushesStylePage,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(styleSelected(const TColorStyle &)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(selectStyle(const TColorStyle &)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_settingsPage, SIGNAL(paramStyleChanged(bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onParamStyleChanged(bool)));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_plainColorPage,
|
|
Shinya Kitaoka |
120a6e |
SIGNAL(colorChanged(const ColorModel &, bool)), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onColorChanged(const ColorModel &, bool)));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/* ------- initial conditions ------- */
|
|
Shinya Kitaoka |
120a6e |
autoCheckChanged(false);
|
|
Shinya Kitaoka |
120a6e |
enable(false, false, false);
|
|
Shinya Kitaoka |
120a6e |
// set to the empty page
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->setCurrentIndex(6);
|
|
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);
|
|
Shinya Kitaoka |
120a6e |
m_autoButton = new QPushButton(tr("Auto \nApply"));
|
|
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"));
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setDisabled(true);
|
|
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"));
|
|
Shinya Kitaoka |
120a6e |
m_autoButton->setChecked(false);
|
|
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;
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setMargin(4);
|
|
Shinya Kitaoka |
120a6e |
mainLayout->setSpacing(10);
|
|
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);
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *buttonsLayout = new QHBoxLayout;
|
|
Shinya Kitaoka |
120a6e |
buttonsLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
buttonsLayout->setSpacing(5);
|
|
Shinya Kitaoka |
120a6e |
{ buttonsLayout->addWidget(m_applyButton); }
|
|
Shinya Kitaoka |
120a6e |
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()));
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::updateTabBar() {
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->clearTabBar();
|
|
Shinya Kitaoka |
120a6e |
if (m_enabled && !m_enabledOnlyFirstTab && !m_enabledFirstAndLastTab) {
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Plain"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Texture"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Special"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Custom"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Vector Brush"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Settings"));
|
|
Shinya Kitaoka |
120a6e |
} else if (m_enabled && m_enabledOnlyFirstTab && !m_enabledFirstAndLastTab)
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Plain"));
|
|
Shinya Kitaoka |
120a6e |
else if (m_enabled && !m_enabledOnlyFirstTab && m_enabledFirstAndLastTab) {
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Plain"));
|
|
Shinya Kitaoka |
120a6e |
m_styleBar->addSimpleTab(tr("Settings"));
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->setCurrentIndex(6);
|
|
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()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged()),
|
|
Shinya Kitaoka |
120a6e |
SLOT(onStyleChanged()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onStyleSwitched()));
|
|
Shinya Kitaoka |
120a6e |
if (m_cleanupPaletteHandle)
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_cleanupPaletteHandle, SIGNAL(colorStyleChanged()),
|
|
Shinya Kitaoka |
120a6e |
SLOT(onCleanupStyleChanged()));
|
|
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 &)));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::hideEvent(QHideEvent *) {
|
|
Shinya Kitaoka |
120a6e |
disconnect(m_paletteHandle);
|
|
Shinya Kitaoka |
120a6e |
if (m_cleanupPaletteHandle) disconnect(m_cleanupPaletteHandle);
|
|
Shinya Kitaoka |
120a6e |
disconnect(m_paletteController);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
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
|
|
Shinya Kitaoka |
120a6e |
m_styleChooser->setCurrentIndex(6);
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
m_statusLabel->setText("- Style not 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)
|
|
Shinya Kitaoka |
120a6e |
statusText = "[CLEANUP] ";
|
|
Shinya Kitaoka |
120a6e |
else if (palette->getGlobalName() != L"")
|
|
Shinya Kitaoka |
120a6e |
statusText = "[STUDIO] ";
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
statusText = "[LEVEL] ";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// palette name
|
|
Shinya Kitaoka |
120a6e |
statusText +=
|
|
Shinya Kitaoka |
120a6e |
QString::fromStdWString(L" Palette : " + palette->getPaletteName());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// style name
|
|
Shinya Kitaoka |
120a6e |
statusText += QString::fromStdWString(L" | Style#");
|
|
Shinya Kitaoka |
120a6e |
statusText += QString::number(styleIndex);
|
|
Shinya Kitaoka |
120a6e |
statusText += QString::fromStdWString(L" : " + m_editedStyle->getName());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_statusLabel->setText(statusText);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
m_statusLabel->setText("- Style is Not Valid -");
|
|
Shinya Kitaoka |
120a6e |
enable(!isStyleNull && isValidIndex, isColorInField, isCleanUpPalette);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::onStyleChanged() {
|
|
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));
|
|
Shinya Kitaoka |
120a6e |
setOldStyleToStyle(
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle
|
|
Shinya Kitaoka |
120a6e |
.getPointer()); // This line is needed for proper undo behavior
|
|
Toshihiro Shimizu |
890ddd |
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
void StyleEditor::onCleanupStyleChanged() {
|
|
Shinya Kitaoka |
120a6e |
if (!m_cleanupPaletteHandle) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
onStyleChanged();
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(
|
|
Shinya Kitaoka |
120a6e |
styleIndex,
|
|
Shinya Kitaoka |
120a6e |
m_editedStyle->clone()); // Must be done *before* setting the eventual
|
|
Shinya Kitaoka |
120a6e |
// 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 |
{
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setEnabled(true);
|
|
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) {
|
|
Shinya Kitaoka |
120a6e |
m_paletteController->enableColorAutoApply(!!value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_enabled) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (value != 0)
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setDisabled(true);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
m_applyButton->setDisabled(false);
|
|
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 |
}
|