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