|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/stylenameeditor.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
160579 |
// TnzQt includes
|
|
shun_iwasawa |
160579 |
#include "toonzqt/gutil.h"
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// TnzLib includes
|
|
shun_iwasawa |
160579 |
#include "toonz/toonzfolders.h"
|
|
shun_iwasawa |
160579 |
#include "toonz/palettecmd.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tpalettehandle.h"
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// TnzCore includes
|
|
shun_iwasawa |
160579 |
#include "tsystem.h"
|
|
shun_iwasawa |
160579 |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.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>
|
|
shun_iwasawa |
160579 |
#include <qgridlayout></qgridlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qlabel></qlabel>
|
|
shun_iwasawa |
160579 |
#include <qscrollarea></qscrollarea>
|
|
shun_iwasawa |
160579 |
#include <qsettings></qsettings>
|
|
shun_iwasawa |
160579 |
#include <qmessagebox></qmessagebox>
|
|
shun_iwasawa |
160579 |
#include <qmenu></qmenu>
|
|
shun_iwasawa |
160579 |
#include <qcontextmenuevent></qcontextmenuevent>
|
|
shun_iwasawa |
160579 |
#include <qframe></qframe>
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------------------------------------------------------------
|
|
shun_iwasawa |
160579 |
namespace {
|
|
shun-iwasawa |
e87e08 |
const int areaColCount[WORD_COLUMN_AMOUNT] = {2, 2, 1};
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
int indexToRow(int index, int columnId) {
|
|
shun_iwasawa |
160579 |
return index / areaColCount[columnId];
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
int indexToCol(int index, int columnId) {
|
|
shun_iwasawa |
160579 |
return index % areaColCount[columnId];
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
}; // namespace
|
|
shun_iwasawa |
160579 |
//------------------------------------------------------------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
NewWordDialog::NewWordDialog(QWidget* parent) {
|
|
shun_iwasawa |
160579 |
setModal(true);
|
|
shun_iwasawa |
160579 |
m_lineEdit = new QLineEdit(this);
|
|
shun_iwasawa |
160579 |
QPushButton* okBtn = new QPushButton(tr("OK"), this);
|
|
shun_iwasawa |
160579 |
QPushButton* cancelBtn = new QPushButton(tr("Cancel"), this);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// layout
|
|
shun_iwasawa |
160579 |
QVBoxLayout* mainLay = new QVBoxLayout();
|
|
shun_iwasawa |
160579 |
mainLay->setMargin(5);
|
|
shun_iwasawa |
160579 |
mainLay->setSpacing(5);
|
|
shun_iwasawa |
160579 |
{
|
|
shun_iwasawa |
160579 |
mainLay->addWidget(new QLabel(tr("Enter new word"), this), 0,
|
|
shun_iwasawa |
160579 |
Qt::AlignLeft | Qt::AlignVCenter);
|
|
shun_iwasawa |
160579 |
mainLay->addWidget(m_lineEdit, 0);
|
|
shun_iwasawa |
160579 |
QHBoxLayout* buttonsLay = new QHBoxLayout();
|
|
shun_iwasawa |
160579 |
buttonsLay->setMargin(3);
|
|
shun_iwasawa |
160579 |
buttonsLay->setSpacing(20);
|
|
shun_iwasawa |
160579 |
{
|
|
shun_iwasawa |
160579 |
buttonsLay->addSpacing(1);
|
|
shun_iwasawa |
160579 |
buttonsLay->addWidget(okBtn, 0);
|
|
shun_iwasawa |
160579 |
buttonsLay->addWidget(cancelBtn, 0);
|
|
shun_iwasawa |
160579 |
buttonsLay->addSpacing(1);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
mainLay->addLayout(buttonsLay);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
setLayout(mainLay);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// signal-slot connections
|
|
shun_iwasawa |
160579 |
bool ret = true;
|
|
shun_iwasawa |
160579 |
ret = ret && connect(okBtn, SIGNAL(clicked(bool)), this, SLOT(accept()));
|
|
shun_iwasawa |
160579 |
ret = ret && connect(cancelBtn, SIGNAL(clicked(bool)), this, SLOT(reject()));
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
QString NewWordDialog::getName() { return m_lineEdit->text(); }
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------------------------------------------------------------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
WordButton::WordButton(const QString& text, QWidget* parent)
|
|
shun_iwasawa |
160579 |
: QPushButton(text, parent) {
|
|
shun_iwasawa |
6c76ac |
setFixedHeight(23);
|
|
shun_iwasawa |
6c76ac |
setMinimumWidth(75);
|
|
shun_iwasawa |
160579 |
setObjectName("WordButton");
|
|
shun_iwasawa |
6c76ac |
setToolTip(text);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
bool ret = connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked()));
|
|
shun_iwasawa |
160579 |
assert(ret);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void WordButton::onClicked() { emit clicked(text()); }
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void WordButton::onRemove() { emit removeWord(text()); }
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void WordButton::contextMenuEvent(QContextMenuEvent* event) {
|
|
shun_iwasawa |
160579 |
QMenu menu(this);
|
|
shun_iwasawa |
160579 |
QAction* removeAct = new QAction(tr("Remove %1").arg(text()), &menu);
|
|
shun_iwasawa |
160579 |
bool ret = connect(removeAct, SIGNAL(triggered()), this, SLOT(onRemove()));
|
|
shun_iwasawa |
160579 |
menu.addAction(removeAct);
|
|
shun_iwasawa |
160579 |
menu.exec(event->globalPos());
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------------------------------------------------------------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
AddWordButton::AddWordButton(const int col, QWidget* parent)
|
|
shun_iwasawa |
0854e8 |
: WordButton(tr("New"), parent), m_column(col) {
|
|
shun-iwasawa |
e87e08 |
static QString columnLabel[WORD_COLUMN_AMOUNT] = {tr("Character"), tr("Part"),
|
|
shun-iwasawa |
e87e08 |
tr("Suffix")};
|
|
shun_iwasawa |
03feed |
// setFixedSize(23, 23);
|
|
Kite |
752c68 |
setIcon(createQIcon("plus"));
|
|
shun_iwasawa |
160579 |
setIconSize(QSize(16, 16));
|
|
shun_iwasawa |
03feed |
setToolTip(tr("Add New Word for %1").arg(columnLabel[col]));
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void AddWordButton::onClicked() { emit clicked(m_column); }
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------------------------------------------------------------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
// load word list from user's settings
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void EasyInputArea::loadList() {
|
|
shun_iwasawa |
160579 |
TFilePath fp(ToonzFolder::getMyModuleDir() +
|
|
shun_iwasawa |
160579 |
TFilePath(styleNameEasyInputWordsFileName));
|
|
shun_iwasawa |
160579 |
if (!TFileStatus(fp).doesExist()) return;
|
|
shun_iwasawa |
160579 |
QSettings wordsSettings(toQString(fp), QSettings::IniFormat);
|
|
shun_iwasawa |
160579 |
for (int a = 0; a < WORD_COLUMN_AMOUNT; a++) {
|
|
shun_iwasawa |
160579 |
int size = wordsSettings.beginReadArray(QString::number(a));
|
|
shun_iwasawa |
160579 |
if (size == 0) continue;
|
|
shun_iwasawa |
160579 |
for (int i = 0; i < size; ++i) {
|
|
shun_iwasawa |
160579 |
wordsSettings.setArrayIndex(i);
|
|
shun_iwasawa |
160579 |
m_wordList[a].append(wordsSettings.value("word").toString());
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
wordsSettings.endArray();
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
// save word list to user's settings
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void EasyInputArea::saveList() {
|
|
shun_iwasawa |
160579 |
TFilePath fp(ToonzFolder::getMyModuleDir() +
|
|
shun_iwasawa |
160579 |
TFilePath(styleNameEasyInputWordsFileName));
|
|
shun_iwasawa |
160579 |
QSettings wordsSettings(toQString(fp), QSettings::IniFormat);
|
|
shun_iwasawa |
160579 |
wordsSettings.clear();
|
|
shun_iwasawa |
160579 |
for (int a = 0; a < WORD_COLUMN_AMOUNT; a++) {
|
|
shun_iwasawa |
160579 |
wordsSettings.beginWriteArray(QString::number(a));
|
|
shun_iwasawa |
03feed |
for (int i = 0; i < m_wordList[a].count(); ++i) {
|
|
shun_iwasawa |
160579 |
wordsSettings.setArrayIndex(i);
|
|
shun_iwasawa |
160579 |
wordsSettings.setValue("word", m_wordList[a].at(i));
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
wordsSettings.endArray();
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void EasyInputArea::updatePanelSize(int columnId) {
|
|
shun_iwasawa |
160579 |
int itemCount = m_wordList[columnId].size() + 1;
|
|
shun_iwasawa |
160579 |
int rowCount = tceil((double)itemCount / (double)areaColCount[columnId]);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
6c76ac |
QWidget* widget = m_scrollArea[columnId]->widget();
|
|
shun_iwasawa |
6c76ac |
widget->setFixedSize(m_scrollArea[columnId]->width(), rowCount * 26 + 3);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
EasyInputArea::EasyInputArea(QWidget* parent) : QWidget(parent) {
|
|
shun_iwasawa |
160579 |
loadList();
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
QHBoxLayout* mainLay = new QHBoxLayout();
|
|
shun_iwasawa |
160579 |
mainLay->setMargin(0);
|
|
shun_iwasawa |
160579 |
mainLay->setSpacing(3);
|
|
shun_iwasawa |
160579 |
for (int a = 0; a < WORD_COLUMN_AMOUNT; a++) {
|
|
shun_iwasawa |
6c76ac |
m_scrollArea[a] = new QScrollArea(this);
|
|
shun_iwasawa |
6c76ac |
m_scrollArea[a]->setObjectName("SolidLineFrame");
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
6c76ac |
QFrame* wordPanel = new QFrame(this);
|
|
shun_iwasawa |
160579 |
QGridLayout* buttonsLay = new QGridLayout();
|
|
shun_iwasawa |
160579 |
buttonsLay->setMargin(3);
|
|
shun_iwasawa |
160579 |
buttonsLay->setSpacing(3);
|
|
shun_iwasawa |
160579 |
{
|
|
shun_iwasawa |
160579 |
int row = 0;
|
|
shun_iwasawa |
160579 |
int col = 0;
|
|
shun_iwasawa |
160579 |
// store word buttons
|
|
shun_iwasawa |
160579 |
for (int s = 0; s < m_wordList[a].size(); s++) {
|
|
shun_iwasawa |
160579 |
WordButton* button = new WordButton(m_wordList[a].at(s), this);
|
|
shun_iwasawa |
03feed |
button->setFocusPolicy(Qt::NoFocus);
|
|
shun_iwasawa |
6c76ac |
buttonsLay->addWidget(button, row, col);
|
|
shun_iwasawa |
160579 |
connect(button, SIGNAL(clicked(const QString&)), this,
|
|
shun_iwasawa |
160579 |
SIGNAL(wordClicked(const QString&)));
|
|
shun_iwasawa |
160579 |
connect(button, SIGNAL(removeWord(const QString&)), this,
|
|
shun_iwasawa |
160579 |
SLOT(onRemoveWord(const QString&)));
|
|
shun_iwasawa |
160579 |
col++;
|
|
shun_iwasawa |
160579 |
if (col == areaColCount[a]) {
|
|
shun_iwasawa |
160579 |
col = 0;
|
|
shun_iwasawa |
160579 |
row++;
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
// add button
|
|
shun_iwasawa |
160579 |
AddWordButton* addWordButton = new AddWordButton(a, this);
|
|
shun_iwasawa |
03feed |
addWordButton->setFocusPolicy(Qt::NoFocus);
|
|
shun_iwasawa |
6c76ac |
buttonsLay->addWidget(addWordButton, row, col);
|
|
shun_iwasawa |
160579 |
connect(addWordButton, SIGNAL(clicked(const int)), this,
|
|
shun_iwasawa |
160579 |
SLOT(addWordButtonClicked(const int)));
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
for (int c = 0; c < areaColCount[a]; c++)
|
|
shun_iwasawa |
160579 |
buttonsLay->setColumnStretch(c, 1);
|
|
shun_iwasawa |
6c76ac |
wordPanel->setLayout(buttonsLay);
|
|
shun_iwasawa |
160579 |
m_wordLayout[a] = buttonsLay;
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
6c76ac |
m_scrollArea[a]->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
shun_iwasawa |
6c76ac |
m_scrollArea[a]->setMinimumWidth(areaColCount[a] * 78 + 3);
|
|
shun_iwasawa |
6c76ac |
m_scrollArea[a]->setWidget(wordPanel);
|
|
shun_iwasawa |
6c76ac |
mainLay->addWidget(m_scrollArea[a], areaColCount[a]);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
setLayout(mainLay);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void EasyInputArea::addWordButtonClicked(const int columnId) {
|
|
shun_iwasawa |
160579 |
NewWordDialog dialog(this);
|
|
shun_iwasawa |
160579 |
if (dialog.exec() == QDialog::Rejected) return;
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
QString word = dialog.getName();
|
|
shun_iwasawa |
160579 |
if (word.isEmpty()) return;
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
bool found = false;
|
|
shun_iwasawa |
160579 |
for (int i = 0; i < WORD_COLUMN_AMOUNT; i++) {
|
|
shun_iwasawa |
160579 |
found = m_wordList[i].contains(word);
|
|
shun_iwasawa |
160579 |
if (found) break;
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
if (found) {
|
|
shun_iwasawa |
160579 |
QMessageBox::warning(this, tr("Warning"),
|
|
shun_iwasawa |
160579 |
tr("%1 is already registered").arg(word));
|
|
shun_iwasawa |
160579 |
return;
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// Append word to the list
|
|
shun_iwasawa |
160579 |
m_wordList[columnId].append(word);
|
|
shun_iwasawa |
160579 |
// Append new WordButton
|
|
shun_iwasawa |
160579 |
WordButton* button = new WordButton(word, this);
|
|
shun_iwasawa |
160579 |
connect(button, SIGNAL(clicked(const QString&)), this,
|
|
shun_iwasawa |
160579 |
SIGNAL(wordClicked(const QString&)));
|
|
shun_iwasawa |
160579 |
connect(button, SIGNAL(removeWord(const QString&)), this,
|
|
shun_iwasawa |
160579 |
SLOT(onRemoveWord(const QString&)));
|
|
shun_iwasawa |
03feed |
button->setFocusPolicy(Qt::NoFocus);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
int wordCount = m_wordList[columnId].count();
|
|
shun_iwasawa |
160579 |
int row = indexToRow(wordCount - 1, columnId);
|
|
shun_iwasawa |
160579 |
int col = indexToCol(wordCount - 1, columnId);
|
|
shun_iwasawa |
160579 |
QWidget* addBtn = m_wordLayout[columnId]->itemAtPosition(row, col)->widget();
|
|
shun_iwasawa |
6c76ac |
m_wordLayout[columnId]->addWidget(button, row, col);
|
|
shun_iwasawa |
160579 |
// Move add button to the next index
|
|
shun_iwasawa |
160579 |
col++;
|
|
shun_iwasawa |
160579 |
if (col == areaColCount[columnId]) {
|
|
shun_iwasawa |
160579 |
col = 0;
|
|
shun_iwasawa |
160579 |
row++;
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
6c76ac |
m_wordLayout[columnId]->addWidget(addBtn, row, col);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
160579 |
updatePanelSize(columnId);
|
|
shun_iwasawa |
03feed |
|
|
shun_iwasawa |
03feed |
saveList();
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------------------------------------------------------------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
void EasyInputArea::onRemoveWord(const QString& word) {
|
|
shun_iwasawa |
160579 |
int a = -1;
|
|
shun_iwasawa |
160579 |
int index;
|
|
shun_iwasawa |
160579 |
for (int i = 0; i < WORD_COLUMN_AMOUNT; i++) {
|
|
shun_iwasawa |
160579 |
index = m_wordList[i].indexOf(word);
|
|
shun_iwasawa |
160579 |
if (index >= 0) {
|
|
shun_iwasawa |
160579 |
a = i;
|
|
shun_iwasawa |
160579 |
break;
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
if (a < 0 || a >= WORD_COLUMN_AMOUNT) return;
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// delete button
|
|
shun_iwasawa |
160579 |
int row = indexToRow(index, a);
|
|
shun_iwasawa |
160579 |
int col = indexToCol(index, a);
|
|
shun_iwasawa |
160579 |
WordButton* wordButton = qobject_cast<wordbutton*>(</wordbutton*>
|
|
shun_iwasawa |
160579 |
m_wordLayout[a]->itemAtPosition(row, col)->widget());
|
|
shun_iwasawa |
160579 |
if (!wordButton) return;
|
|
shun_iwasawa |
160579 |
bool ret = true;
|
|
shun_iwasawa |
160579 |
ret = ret && disconnect(wordButton, SIGNAL(clicked(const QString&)), this,
|
|
shun_iwasawa |
160579 |
SIGNAL(wordClicked(const QString&)));
|
|
shun_iwasawa |
160579 |
ret = ret && disconnect(wordButton, SIGNAL(removeWord(const QString&)), this,
|
|
shun_iwasawa |
160579 |
SLOT(onRemoveWord(const QString&)));
|
|
shun_iwasawa |
160579 |
assert(ret);
|
|
shun_iwasawa |
160579 |
m_wordLayout[a]->removeWidget(wordButton);
|
|
shun_iwasawa |
160579 |
wordButton->deleteLater();
|
|
shun_iwasawa |
160579 |
// move the following buttons
|
|
shun_iwasawa |
160579 |
for (int i = index + 1; i <= m_wordList[a].count(); i++) {
|
|
shun_iwasawa |
160579 |
int row = indexToRow(i, a);
|
|
shun_iwasawa |
160579 |
int col = indexToCol(i, a);
|
|
shun_iwasawa |
160579 |
QWidget* button = m_wordLayout[a]->itemAtPosition(row, col)->widget();
|
|
shun_iwasawa |
160579 |
col--;
|
|
shun_iwasawa |
160579 |
if (col < 0) {
|
|
shun_iwasawa |
160579 |
row--;
|
|
shun_iwasawa |
160579 |
col = areaColCount[a] - 1;
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
6c76ac |
m_wordLayout[a]->addWidget(button, row, col);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// remove word from the list
|
|
shun_iwasawa |
160579 |
m_wordList[a].removeAt(index);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
updatePanelSize(a);
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//------------------------------------------------------------
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
03feed |
void EasyInputArea::enterEvent(QEvent*) { emit mouseEnter(); }
|
|
shun_iwasawa |
03feed |
|
|
shun_iwasawa |
03feed |
//------------------------------------------------------------
|
|
shun_iwasawa |
03feed |
|
|
shun_iwasawa |
6c76ac |
void EasyInputArea::resizeEvent(QResizeEvent*) {
|
|
shun_iwasawa |
6c76ac |
for (int i = 0; i < WORD_COLUMN_AMOUNT; i++) {
|
|
shun_iwasawa |
6c76ac |
updatePanelSize(i);
|
|
shun_iwasawa |
6c76ac |
}
|
|
shun_iwasawa |
6c76ac |
}
|
|
shun_iwasawa |
6c76ac |
|
|
shun_iwasawa |
6c76ac |
//------------------------------------------------------------
|
|
shun_iwasawa |
6c76ac |
|
|
shun_iwasawa |
160579 |
StyleNameEditor::StyleNameEditor(QWidget* parent)
|
|
shun_iwasawa |
03feed |
: Dialog(parent, false, false, "StyleNameEditor")
|
|
shun_iwasawa |
03feed |
, m_paletteHandle(0)
|
|
shun_iwasawa |
03feed |
, m_selectionStart(-1)
|
|
shun_iwasawa |
03feed |
, m_selectionLength(0) {
|
|
shun-iwasawa |
e87e08 |
QString columnLabel[WORD_COLUMN_AMOUNT] = {AddWordButton::tr("Character"),
|
|
shun-iwasawa |
e87e08 |
AddWordButton::tr("Part"),
|
|
shun-iwasawa |
e87e08 |
AddWordButton::tr("Suffix")};
|
|
shun-iwasawa |
e87e08 |
|
|
Shinya Kitaoka |
120a6e |
setWindowTitle(tr("Name Editor"));
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
160579 |
m_styleName = new QLineEdit(this);
|
|
shun_iwasawa |
160579 |
m_okButton = new QPushButton(tr("OK"), this);
|
|
shun_iwasawa |
160579 |
m_cancelButton = new QPushButton(tr("Cancel"), this);
|
|
shun_iwasawa |
160579 |
m_applyButton = new QPushButton(tr("Apply and Next"), this);
|
|
shun_iwasawa |
160579 |
EasyInputArea* easyInputArea = new EasyInputArea(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
0854e8 |
QLabel* panelLabel[WORD_COLUMN_AMOUNT];
|
|
shun_iwasawa |
0854e8 |
for (int i = 0; i < WORD_COLUMN_AMOUNT; i++) {
|
|
shun_iwasawa |
0854e8 |
panelLabel[i] = new QLabel(columnLabel[i], this);
|
|
shun_iwasawa |
0854e8 |
panelLabel[i]->setStyleSheet("font-size: 10px; font: italic;");
|
|
shun_iwasawa |
0854e8 |
}
|
|
shun_iwasawa |
0854e8 |
|
|
shun_iwasawa |
03feed |
setFocusProxy(m_styleName);
|
|
shun_iwasawa |
03feed |
|
|
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);
|
|
shun_iwasawa |
03feed |
m_applyButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
m_cancelButton->setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
21a6b6 |
m_styleName->setObjectName("LargeSizedText");
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
03feed |
easyInputArea->setFocusPolicy(Qt::NoFocus);
|
|
shun_iwasawa |
03feed |
|
|
shun_iwasawa |
03feed |
// QVBoxLayout* mainLayout = new QVBoxLayout();
|
|
shun_iwasawa |
03feed |
m_topLayout->setMargin(10);
|
|
shun_iwasawa |
03feed |
m_topLayout->setSpacing(5);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
shun_iwasawa |
160579 |
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 |
}
|
|
shun_iwasawa |
03feed |
m_topLayout->addLayout(inputLayout, 0);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
160579 |
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 |
}
|
|
shun_iwasawa |
03feed |
m_topLayout->addLayout(buttonLayout, 0);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
03feed |
m_topLayout->addSpacing(5);
|
|
shun_iwasawa |
0854e8 |
|
|
shun_iwasawa |
0854e8 |
QHBoxLayout* labelLay = new QHBoxLayout();
|
|
shun_iwasawa |
0854e8 |
labelLay->setMargin(0);
|
|
shun_iwasawa |
0854e8 |
labelLay->setSpacing(3);
|
|
shun_iwasawa |
0854e8 |
{
|
|
shun_iwasawa |
0854e8 |
labelLay->addWidget(new QLabel(tr("Easy Inputs"), this), 1,
|
|
shun_iwasawa |
0854e8 |
Qt::AlignLeft);
|
|
shun_iwasawa |
0854e8 |
for (int i = 0; i < WORD_COLUMN_AMOUNT; i++) {
|
|
shun_iwasawa |
0854e8 |
labelLay->addWidget(panelLabel[i],
|
|
shun_iwasawa |
0854e8 |
(i == 0) ? areaColCount[i] - 1 : areaColCount[i],
|
|
shun_iwasawa |
0854e8 |
Qt::AlignRight | Qt::AlignBottom);
|
|
shun_iwasawa |
0854e8 |
}
|
|
shun_iwasawa |
0854e8 |
}
|
|
shun_iwasawa |
0854e8 |
m_topLayout->addLayout(labelLay, 0);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
03feed |
m_topLayout->addWidget(easyInputArea, 1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
160579 |
bool ret = true;
|
|
shun_iwasawa |
160579 |
ret =
|
|
shun_iwasawa |
160579 |
ret && connect(m_okButton, SIGNAL(pressed()), this, SLOT(onOkPressed()));
|
|
shun_iwasawa |
160579 |
ret = ret && connect(m_cancelButton, SIGNAL(pressed()), this,
|
|
shun_iwasawa |
160579 |
SLOT(onCancelPressed()));
|
|
shun_iwasawa |
160579 |
ret = ret &&
|
|
shun_iwasawa |
160579 |
connect(m_applyButton, SIGNAL(pressed()), this, SLOT(onApplyPressed()));
|
|
shun_iwasawa |
160579 |
ret = ret && connect(easyInputArea, SIGNAL(wordClicked(const QString&)), this,
|
|
shun_iwasawa |
160579 |
SLOT(onWordClicked(const QString&)));
|
|
shun_iwasawa |
03feed |
ret = ret && connect(easyInputArea, SIGNAL(mouseEnter()), this,
|
|
shun_iwasawa |
03feed |
SLOT(storeSelectionInfo()));
|
|
shun_iwasawa |
160579 |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------
|
|
shun_iwasawa |
160579 |
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 |
//-------
|
|
shun_iwasawa |
160579 |
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
|
|
shun_iwasawa |
160579 |
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();
|
|
shun_iwasawa |
03feed |
m_styleName->setFocus();
|
|
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 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
Shinya Kitaoka |
120a6e |
void StyleNameEditor::onOkPressed() {
|
|
Shinya Kitaoka |
120a6e |
onApplyPressed();
|
|
Shinya Kitaoka |
120a6e |
close();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
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);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// move the current style to the next
|
|
shun_iwasawa |
160579 |
TPalette* palette = m_paletteHandle->getPalette();
|
|
shun_iwasawa |
160579 |
int currentIndex = m_paletteHandle->getStyleIndex();
|
|
shun_iwasawa |
160579 |
TPalette::Page* page = palette->getStylePage(currentIndex);
|
|
shun_iwasawa |
160579 |
int indexInPage = page->search(currentIndex);
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
// If indexInPage is at the end of the page, then move to the top of the next
|
|
shun_iwasawa |
160579 |
// page
|
|
shun_iwasawa |
160579 |
if (indexInPage == page->getStyleCount() - 1) {
|
|
shun_iwasawa |
160579 |
int pageIndex = page->getIndex();
|
|
shun_iwasawa |
160579 |
// if the current page is the last one, then move to the first page
|
|
shun_iwasawa |
160579 |
while (1) {
|
|
shun_iwasawa |
160579 |
pageIndex++;
|
|
shun_iwasawa |
160579 |
if (pageIndex == palette->getPageCount()) pageIndex = 0;
|
|
shun_iwasawa |
160579 |
page = palette->getPage(pageIndex);
|
|
shun_iwasawa |
160579 |
if (page->getStyleCount() > 0) break;
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
currentIndex = page->getStyleId(0);
|
|
shun_iwasawa |
160579 |
} else
|
|
shun_iwasawa |
160579 |
currentIndex = page->getStyleId(indexInPage + 1);
|
|
shun_iwasawa |
160579 |
// change the current index
|
|
shun_iwasawa |
160579 |
m_paletteHandle->setStyleIndex(currentIndex);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
160579 |
//-------
|
|
Shinya Kitaoka |
120a6e |
void StyleNameEditor::onCancelPressed() { close(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
160579 |
//-------
|
|
Shinya Kitaoka |
120a6e |
// focus when the mouse enters
|
|
shun_iwasawa |
160579 |
void StyleNameEditor::enterEvent(QEvent* e) {
|
|
Shinya Kitaoka |
120a6e |
activateWindow();
|
|
Shinya Kitaoka |
120a6e |
m_styleName->setFocus();
|
|
shun_iwasawa |
160579 |
}
|
|
shun_iwasawa |
160579 |
|
|
shun_iwasawa |
160579 |
//-------
|
|
shun_iwasawa |
160579 |
void StyleNameEditor::onWordClicked(const QString& word) {
|
|
shun_iwasawa |
03feed |
if (m_selectionLength != 0)
|
|
shun_iwasawa |
03feed |
m_styleName->setSelection(m_selectionStart, m_selectionLength);
|
|
shun_iwasawa |
03feed |
else
|
|
shun_iwasawa |
03feed |
m_styleName->setCursorPosition(m_selectionStart);
|
|
shun_iwasawa |
03feed |
|
|
shun_iwasawa |
160579 |
m_styleName->insert(word);
|
|
shun_iwasawa |
03feed |
m_styleName->setFocus();
|
|
shun_iwasawa |
03feed |
|
|
shun_iwasawa |
03feed |
storeSelectionInfo();
|
|
shun_iwasawa |
03feed |
}
|
|
shun_iwasawa |
03feed |
|
|
shun_iwasawa |
03feed |
//-------
|
|
shun_iwasawa |
03feed |
// remember the selection of m_stylename when mouse entered in EasyInputArea
|
|
shun_iwasawa |
03feed |
void StyleNameEditor::storeSelectionInfo() {
|
|
shun_iwasawa |
03feed |
if (m_styleName->hasSelectedText()) {
|
|
shun_iwasawa |
03feed |
m_selectionStart = m_styleName->selectionStart();
|
|
shun_iwasawa |
03feed |
m_selectionLength = m_styleName->selectedText().length();
|
|
shun_iwasawa |
03feed |
} else {
|
|
shun_iwasawa |
03feed |
m_selectionStart = m_styleName->cursorPosition();
|
|
shun_iwasawa |
03feed |
m_selectionLength = 0;
|
|
shun_iwasawa |
03feed |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|