|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/stylenameeditor.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tpalettehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/palettecmd.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <qlineedit></qlineedit>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpushbutton></qpushbutton>
|
|
Toshihiro Shimizu |
890ddd |
#include <qhboxlayout></qhboxlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qvboxlayout></qvboxlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qlabel></qlabel>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
StyleNameEditor::StyleNameEditor(QWidget *parent)
|
|
Toshihiro Shimizu |
890ddd |
: QDialog(parent), m_paletteHandle(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setWindowTitle(tr("Name Editor"));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_styleName = new QLineEdit(this);
|
|
Toshihiro Shimizu |
890ddd |
m_okButton = new QPushButton(tr("OK"), this);
|
|
Toshihiro Shimizu |
890ddd |
m_cancelButton = new QPushButton(tr("Cancel"), this);
|
|
Toshihiro Shimizu |
890ddd |
m_applyButton = new QPushButton(tr("Apply"), this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_styleName->setEnabled(false);
|
|
Toshihiro Shimizu |
890ddd |
m_okButton->setEnabled(false);
|
|
Toshihiro Shimizu |
890ddd |
m_okButton->setFocusPolicy(Qt::NoFocus);
|
|
Toshihiro Shimizu |
890ddd |
m_applyButton->setEnabled(false);
|
|
Toshihiro Shimizu |
890ddd |
m_cancelButton->setFocusPolicy(Qt::NoFocus);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_styleName->setObjectName("RenameColorTextField");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QVBoxLayout *mainLayout = new QVBoxLayout();
|
|
Toshihiro Shimizu |
890ddd |
mainLayout->setMargin(10);
|
|
Toshihiro Shimizu |
890ddd |
mainLayout->setSpacing(5);
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QHBoxLayout *inputLayout = new QHBoxLayout();
|
|
Toshihiro Shimizu |
890ddd |
inputLayout->setMargin(0);
|
|
Toshihiro Shimizu |
890ddd |
inputLayout->setSpacing(3);
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
inputLayout->addWidget(new QLabel(tr("Style Name"), this), 0);
|
|
Toshihiro Shimizu |
890ddd |
inputLayout->addWidget(m_styleName, 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
mainLayout->addLayout(inputLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
|
Toshihiro Shimizu |
890ddd |
buttonLayout->setMargin(0);
|
|
Toshihiro Shimizu |
890ddd |
buttonLayout->setSpacing(3);
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
buttonLayout->addWidget(m_okButton);
|
|
Toshihiro Shimizu |
890ddd |
buttonLayout->addWidget(m_applyButton);
|
|
Toshihiro Shimizu |
890ddd |
buttonLayout->addWidget(m_cancelButton);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
mainLayout->addLayout(buttonLayout);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
setLayout(mainLayout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
setGeometry(640, 512, 420, 80);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
connect(m_okButton, SIGNAL(pressed()), this, SLOT(onOkPressed()));
|
|
Toshihiro Shimizu |
890ddd |
connect(m_cancelButton, SIGNAL(pressed()), this, SLOT(onCancelPressed()));
|
|
Toshihiro Shimizu |
890ddd |
connect(m_applyButton, SIGNAL(pressed()), this, SLOT(onApplyPressed()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::setPaletteHandle(TPaletteHandle *ph)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_paletteHandle = ph;
|
|
Toshihiro Shimizu |
890ddd |
connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
connect(m_paletteHandle, SIGNAL(paletteSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
m_styleName->setEnabled(true);
|
|
Toshihiro Shimizu |
890ddd |
m_okButton->setEnabled(true);
|
|
Toshihiro Shimizu |
890ddd |
m_applyButton->setEnabled(true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::showEvent(QShowEvent *e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_paletteHandle) {
|
|
Toshihiro Shimizu |
890ddd |
disconnect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
disconnect(m_paletteHandle, SIGNAL(paletteSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
connect(m_paletteHandle, SIGNAL(paletteSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//update view
|
|
Toshihiro Shimizu |
890ddd |
onStyleSwitched();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------disconnection
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::hideEvent(QHideEvent *e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
disconnect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
disconnect(m_paletteHandle, SIGNAL(paletteSwitched()), this, SLOT(onStyleSwitched()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----update display when the current style is switched
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::onStyleSwitched()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_paletteHandle || !m_paletteHandle->getStyle())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
wstring styleName = m_paletteHandle->getStyle()->getName();
|
|
Toshihiro Shimizu |
890ddd |
m_styleName->setText(QString::fromStdWString(styleName));
|
|
Toshihiro Shimizu |
890ddd |
m_styleName->selectAll();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int styleId = m_paletteHandle->getStyleIndex();
|
|
Toshihiro Shimizu |
890ddd |
setWindowTitle(tr("Name Editor: # %1").arg(styleId));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::onOkPressed()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
onApplyPressed();
|
|
Toshihiro Shimizu |
890ddd |
close();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::onApplyPressed()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_paletteHandle || !m_paletteHandle->getStyle())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (m_styleName->text() == "")
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
wstring newName = m_styleName->text().toStdWString();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
PaletteCmd::renamePaletteStyle(m_paletteHandle, newName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::onCancelPressed()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
close();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//focus when the mouse enters
|
|
Toshihiro Shimizu |
890ddd |
void StyleNameEditor::enterEvent(QEvent *e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
activateWindow();
|
|
Toshihiro Shimizu |
890ddd |
m_styleName->setFocus();
|
|
Toshihiro Shimizu |
890ddd |
}
|