easy input for name editor

This commit is contained in:
shun_iwasawa 2016-11-10 22:41:11 +09:00
parent 3bb5efc4ee
commit 16057916f3
14 changed files with 762 additions and 23 deletions

View file

@ -31,6 +31,13 @@
background-color: lighten(@m_baseBG, @light);
}
.set_border_color(@lefttop, @rightbottom){
border-left-color: @lefttop;
border-top-color: @lefttop;
border-right-color: @rightbottom;
border-bottom-color: @rightbottom;
}
.base_inset(@dark: 0%){
.baseBG(@dark);
border-style: inset;
@ -1375,4 +1382,28 @@ QDialog #dialogButtonFrame {
&:hover {
.baseBG(light, 10%);
}
}
#WordButton {
font-size: 12px;
color: black;
background-color: rgb(192, 192, 192);
border-style: outset;
.set_border_color(white,black);
border-width: 1px;
border-radius: 1px;
.set_padding(3px, 3px);
&:pressed {
background-color: rgb(250, 255, 162);
border-style: inset;
.set_border_color(black,white);
}
&:hover {
background-color: rgb(250, 255, 162);
&:pressed {
background-color: rgb(250, 255, 162);
border-style: inset;
.set_border_color(black,white);
}
}
}

View file

@ -1378,5 +1378,40 @@ QDialog #dialogButtonFrame {
#StartupLabel:hover {
background-color: #4a4a4a;
}
#WordButton {
font-size: 12px;
color: black;
background-color: #c0c0c0;
border-style: outset;
border-left-color: white;
border-top-color: white;
border-right-color: black;
border-bottom-color: black;
border-width: 1px;
border-radius: 1px;
padding-left: 3px;
padding-right: 3px;
padding-top: 3px;
padding-bottom: 3px;
}
#WordButton:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
#WordButton:hover {
background-color: #faffa2;
}
#WordButton:hover:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
//# sourceMappingURL=gray_048.qss.map

View file

@ -1378,5 +1378,40 @@ QDialog #dialogButtonFrame {
#StartupLabel:hover {
background-color: #4a4a4a;
}
#WordButton {
font-size: 12px;
color: black;
background-color: #c0c0c0;
border-style: outset;
border-left-color: white;
border-top-color: white;
border-right-color: black;
border-bottom-color: black;
border-width: 1px;
border-radius: 1px;
padding-left: 3px;
padding-right: 3px;
padding-top: 3px;
padding-bottom: 3px;
}
#WordButton:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
#WordButton:hover {
background-color: #faffa2;
}
#WordButton:hover:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
//# sourceMappingURL=gray_048_mac.qss.map

View file

@ -29,7 +29,12 @@
.baseBG(light, @light: 0%){
background-color: lighten(@m_baseBG, @light);
}
.set_border_color(@lefttop, @rightbottom){
border-left-color: @lefttop;
border-top-color: @lefttop;
border-right-color: @rightbottom;
border-bottom-color: @rightbottom;
}
.base_inset(@dark: 0%){
.baseBG(@dark);
border-style: inset;
@ -1375,4 +1380,28 @@ QDialog #dialogButtonFrame {
&:hover {
.baseBG(light, 10%);
}
}
#WordButton {
font-size: 12px;
color: black;
background-color: rgb(192, 192, 192);
border-style: outset;
.set_border_color(white,black);
border-width: 1px;
border-radius: 1px;
.set_padding(3px, 3px);
&:pressed {
background-color: rgb(250, 255, 162);
border-style: inset;
.set_border_color(black,white);
}
&:hover {
background-color: rgb(250, 255, 162);
&:pressed {
background-color: rgb(250, 255, 162);
border-style: inset;
.set_border_color(black,white);
}
}
}

View file

@ -1378,5 +1378,40 @@ QDialog #dialogButtonFrame {
#StartupLabel:hover {
background-color: #626262;
}
#WordButton {
font-size: 12px;
color: black;
background-color: #c0c0c0;
border-style: outset;
border-left-color: white;
border-top-color: white;
border-right-color: black;
border-bottom-color: black;
border-width: 1px;
border-radius: 1px;
padding-left: 3px;
padding-right: 3px;
padding-top: 3px;
padding-bottom: 3px;
}
#WordButton:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
#WordButton:hover {
background-color: #faffa2;
}
#WordButton:hover:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
//# sourceMappingURL=gray_072.qss.map

View file

@ -1378,5 +1378,40 @@ QDialog #dialogButtonFrame {
#StartupLabel:hover {
background-color: #626262;
}
#WordButton {
font-size: 12px;
color: black;
background-color: #c0c0c0;
border-style: outset;
border-left-color: white;
border-top-color: white;
border-right-color: black;
border-bottom-color: black;
border-width: 1px;
border-radius: 1px;
padding-left: 3px;
padding-right: 3px;
padding-top: 3px;
padding-bottom: 3px;
}
#WordButton:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
#WordButton:hover {
background-color: #faffa2;
}
#WordButton:hover:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
//# sourceMappingURL=gray_072_mac.qss.map

View file

@ -17,7 +17,12 @@
.baseBG(light, @light: 0%){
background-color: lighten(@m_baseBG, @light);
}
.set_border_color(@lefttop, @rightbottom){
border-left-color: @lefttop;
border-top-color: @lefttop;
border-right-color: @rightbottom;
border-bottom-color: @rightbottom;
}
.base_inset(@dark: 0%){
.baseBG(@dark);
border-style: inset;
@ -1201,4 +1206,28 @@ QDialog #dialogButtonFrame {
&:hover {
.baseBG(light, 10%);
}
}
#WordButton {
font-size: 12px;
color: black;
background-color: rgb(192, 192, 192);
border-style: outset;
.set_border_color(white,black);
border-width: 1px;
border-radius: 1px;
.set_padding(3px, 3px);
&:pressed {
background-color: rgb(250, 255, 162);
border-style: inset;
.set_border_color(black,white);
}
&:hover {
background-color: rgb(250, 255, 162);
&:pressed {
background-color: rgb(250, 255, 162);
border-style: inset;
.set_border_color(black,white);
}
}
}

View file

@ -1117,5 +1117,40 @@ QDialog #dialogButtonFrame {
#StartupLabel:hover {
background-color: #9a9a9a;
}
#WordButton {
font-size: 12px;
color: black;
background-color: #c0c0c0;
border-style: outset;
border-left-color: white;
border-top-color: white;
border-right-color: black;
border-bottom-color: black;
border-width: 1px;
border-radius: 1px;
padding-left: 3px;
padding-right: 3px;
padding-top: 3px;
padding-bottom: 3px;
}
#WordButton:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
#WordButton:hover {
background-color: #faffa2;
}
#WordButton:hover:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
//# sourceMappingURL=gray_128.qss.map

View file

@ -1117,5 +1117,40 @@ QDialog #dialogButtonFrame {
#StartupLabel:hover {
background-color: #9a9a9a;
}
#WordButton {
font-size: 12px;
color: black;
background-color: #c0c0c0;
border-style: outset;
border-left-color: white;
border-top-color: white;
border-right-color: black;
border-bottom-color: black;
border-width: 1px;
border-radius: 1px;
padding-left: 3px;
padding-right: 3px;
padding-top: 3px;
padding-bottom: 3px;
}
#WordButton:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
#WordButton:hover {
background-color: #faffa2;
}
#WordButton:hover:pressed {
background-color: #faffa2;
border-style: inset;
border-left-color: black;
border-top-color: black;
border-right-color: white;
border-bottom-color: white;
}
//# sourceMappingURL=gray_128_mac.qss.map

View file

@ -181,6 +181,7 @@ inline std::ostream &operator<<(std::ostream &out, const std::string &s) {
#define tArrayCount(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
const std::string mySettingsFileName = "mysettings.ini";
const std::string mySettingsFileName = "mysettings.ini";
const std::string styleNameEasyInputWordsFileName = "stylename_easyinput.ini";
#endif //__T_COMMON_INCLUDED

View file

@ -4,10 +4,91 @@
#define STYLENAMEEDITOR_H
#include <QDialog>
#include <QWidget>
#include <QStringList>
#include <QPushButton>
class QLineEdit;
class QPushButton;
class TPaletteHandle;
class QGridLayout;
class QFrame;
const int WORD_COLUMN_AMOUNT = 3;
//------------------------------------------------------------
class NewWordDialog : public QDialog {
Q_OBJECT
QLineEdit *m_lineEdit;
public:
NewWordDialog(QWidget *parent = Q_NULLPTR);
QString getName();
};
//------------------------------------------------------------
class WordButton : public QPushButton {
Q_OBJECT
public:
WordButton(const QString &text, QWidget *parent = Q_NULLPTR);
protected:
void contextMenuEvent(QContextMenuEvent *) override;
protected slots:
virtual void onClicked();
void onRemove();
signals:
void clicked(const QString &);
void removeWord(const QString &);
};
//------------------------------------------------------------
class AddWordButton final : public WordButton {
Q_OBJECT
int m_column;
public:
AddWordButton(const int col, QWidget *parent = Q_NULLPTR);
protected slots:
void onClicked() override;
void contextMenuEvent(QContextMenuEvent *) override{};
signals:
void clicked(const int);
};
//------------------------------------------------------------
class EasyInputArea final : public QWidget {
Q_OBJECT
QStringList m_wordList[WORD_COLUMN_AMOUNT];
QGridLayout *m_wordLayout[WORD_COLUMN_AMOUNT];
QFrame *m_wordPanel[WORD_COLUMN_AMOUNT];
void loadList();
void saveList();
void updatePanelSize(int columnId);
public:
EasyInputArea(QWidget *parent = 0);
~EasyInputArea();
protected slots:
void addWordButtonClicked(const int);
void onRemoveWord(const QString &);
signals:
void wordClicked(const QString &);
};
//------------------------------------------------------------
class StyleNameEditor final : public QDialog // singleton
{
@ -32,6 +113,7 @@ protected slots:
void onOkPressed();
void onApplyPressed();
void onCancelPressed();
void onWordClicked(const QString &);
};
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1,25 +1,335 @@
#include "toonzqt/stylenameeditor.h"
#include "tcommon.h"
// TnzQt includes
#include "toonzqt/gutil.h"
// TnzLib includes
#include "toonz/toonzfolders.h"
#include "toonz/palettecmd.h"
#include "toonz/tpalettehandle.h"
// TnzCore includes
#include "tsystem.h"
#include "tcommon.h"
#include "tcolorstyles.h"
#include "tpalette.h"
#include "toonz/palettecmd.h"
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QScrollArea>
#include <QSettings>
#include <QMessageBox>
#include <QMenu>
#include <QContextMenuEvent>
#include <QFrame>
StyleNameEditor::StyleNameEditor(QWidget *parent)
//------------------------------------------------------------
namespace {
const int areaColCount[WORD_COLUMN_AMOUNT] = {2, 2, 1};
int indexToRow(int index, int columnId) {
return index / areaColCount[columnId];
}
int indexToCol(int index, int columnId) {
return index % areaColCount[columnId];
}
}; // namespace
//------------------------------------------------------------
NewWordDialog::NewWordDialog(QWidget* parent) {
setModal(true);
m_lineEdit = new QLineEdit(this);
QPushButton* okBtn = new QPushButton(tr("OK"), this);
QPushButton* cancelBtn = new QPushButton(tr("Cancel"), this);
// layout
QVBoxLayout* mainLay = new QVBoxLayout();
mainLay->setMargin(5);
mainLay->setSpacing(5);
{
mainLay->addWidget(new QLabel(tr("Enter new word"), this), 0,
Qt::AlignLeft | Qt::AlignVCenter);
mainLay->addWidget(m_lineEdit, 0);
QHBoxLayout* buttonsLay = new QHBoxLayout();
buttonsLay->setMargin(3);
buttonsLay->setSpacing(20);
{
buttonsLay->addSpacing(1);
buttonsLay->addWidget(okBtn, 0);
buttonsLay->addWidget(cancelBtn, 0);
buttonsLay->addSpacing(1);
}
mainLay->addLayout(buttonsLay);
}
setLayout(mainLay);
// signal-slot connections
bool ret = true;
ret = ret && connect(okBtn, SIGNAL(clicked(bool)), this, SLOT(accept()));
ret = ret && connect(cancelBtn, SIGNAL(clicked(bool)), this, SLOT(reject()));
}
//-------
QString NewWordDialog::getName() { return m_lineEdit->text(); }
//------------------------------------------------------------
WordButton::WordButton(const QString& text, QWidget* parent)
: QPushButton(text, parent) {
setFixedSize(75, 23);
setObjectName("WordButton");
bool ret = connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked()));
assert(ret);
}
//-------
void WordButton::onClicked() { emit clicked(text()); }
//-------
void WordButton::onRemove() { emit removeWord(text()); }
//-------
void WordButton::contextMenuEvent(QContextMenuEvent* event) {
QMenu menu(this);
QAction* removeAct = new QAction(tr("Remove %1").arg(text()), &menu);
bool ret = connect(removeAct, SIGNAL(triggered()), this, SLOT(onRemove()));
menu.addAction(removeAct);
menu.exec(event->globalPos());
}
//------------------------------------------------------------
AddWordButton::AddWordButton(const int col, QWidget* parent)
: WordButton("", parent), m_column(col) {
setFixedSize(23, 23);
setIcon(QIcon(":Resources/plus.png"));
setIconSize(QSize(16, 16));
setToolTip(tr("Add New Word"));
}
//-------
void AddWordButton::onClicked() { emit clicked(m_column); }
//------------------------------------------------------------
//-------
// load word list from user's settings
void EasyInputArea::loadList() {
TFilePath fp(ToonzFolder::getMyModuleDir() +
TFilePath(styleNameEasyInputWordsFileName));
if (!TFileStatus(fp).doesExist()) return;
QSettings wordsSettings(toQString(fp), QSettings::IniFormat);
for (int a = 0; a < WORD_COLUMN_AMOUNT; a++) {
int size = wordsSettings.beginReadArray(QString::number(a));
if (size == 0) continue;
for (int i = 0; i < size; ++i) {
wordsSettings.setArrayIndex(i);
m_wordList[a].append(wordsSettings.value("word").toString());
}
wordsSettings.endArray();
}
}
//-------
// save word list to user's settings
void EasyInputArea::saveList() {
TFilePath fp(ToonzFolder::getMyModuleDir() +
TFilePath(styleNameEasyInputWordsFileName));
QSettings wordsSettings(toQString(fp), QSettings::IniFormat);
wordsSettings.clear();
for (int a = 0; a < WORD_COLUMN_AMOUNT; a++) {
wordsSettings.beginWriteArray(QString::number(a));
for (int i = 0; i < m_wordList[a].size(); ++i) {
wordsSettings.setArrayIndex(i);
wordsSettings.setValue("word", m_wordList[a].at(i));
}
wordsSettings.endArray();
}
}
//------
void EasyInputArea::updatePanelSize(int columnId) {
int itemCount = m_wordList[columnId].size() + 1;
int rowCount = tceil((double)itemCount / (double)areaColCount[columnId]);
m_wordPanel[columnId]->setFixedSize(areaColCount[columnId] * 78 + 3,
rowCount * 26 + 3);
}
//------
EasyInputArea::EasyInputArea(QWidget* parent) : QWidget(parent) {
loadList();
QHBoxLayout* mainLay = new QHBoxLayout();
mainLay->setMargin(0);
mainLay->setSpacing(3);
for (int a = 0; a < WORD_COLUMN_AMOUNT; a++) {
QScrollArea* scrollArea = new QScrollArea(this);
scrollArea->setObjectName("SolidLineFrame");
m_wordPanel[a] = new QFrame(this);
QGridLayout* buttonsLay = new QGridLayout();
buttonsLay->setMargin(3);
buttonsLay->setSpacing(3);
{
int row = 0;
int col = 0;
// store word buttons
for (int s = 0; s < m_wordList[a].size(); s++) {
WordButton* button = new WordButton(m_wordList[a].at(s), this);
buttonsLay->addWidget(button, row, col, Qt::AlignCenter);
connect(button, SIGNAL(clicked(const QString&)), this,
SIGNAL(wordClicked(const QString&)));
connect(button, SIGNAL(removeWord(const QString&)), this,
SLOT(onRemoveWord(const QString&)));
col++;
if (col == areaColCount[a]) {
col = 0;
row++;
}
}
// add button
AddWordButton* addWordButton = new AddWordButton(a, this);
buttonsLay->addWidget(addWordButton, row, col, Qt::AlignCenter);
connect(addWordButton, SIGNAL(clicked(const int)), this,
SLOT(addWordButtonClicked(const int)));
}
for (int c = 0; c < areaColCount[a]; c++)
buttonsLay->setColumnStretch(c, 1);
m_wordPanel[a]->setLayout(buttonsLay);
m_wordLayout[a] = buttonsLay;
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setWidget(m_wordPanel[a]);
mainLay->addWidget(scrollArea, 0);
updatePanelSize(a);
scrollArea->setFixedWidth(m_wordPanel[a]->width());
}
mainLay->addStretch(1);
setLayout(mainLay);
}
//-------
EasyInputArea::~EasyInputArea() { saveList(); }
//-------
void EasyInputArea::addWordButtonClicked(const int columnId) {
NewWordDialog dialog(this);
if (dialog.exec() == QDialog::Rejected) return;
QString word = dialog.getName();
if (word.isEmpty()) return;
bool found = false;
for (int i = 0; i < WORD_COLUMN_AMOUNT; i++) {
found = m_wordList[i].contains(word);
if (found) break;
}
if (found) {
QMessageBox::warning(this, tr("Warning"),
tr("%1 is already registered").arg(word));
return;
}
// Append word to the list
m_wordList[columnId].append(word);
// Append new WordButton
WordButton* button = new WordButton(word, this);
connect(button, SIGNAL(clicked(const QString&)), this,
SIGNAL(wordClicked(const QString&)));
connect(button, SIGNAL(removeWord(const QString&)), this,
SLOT(onRemoveWord(const QString&)));
int wordCount = m_wordList[columnId].count();
int row = indexToRow(wordCount - 1, columnId);
int col = indexToCol(wordCount - 1, columnId);
QWidget* addBtn = m_wordLayout[columnId]->itemAtPosition(row, col)->widget();
m_wordLayout[columnId]->addWidget(button, row, col, Qt::AlignCenter);
// Move add button to the next index
col++;
if (col == areaColCount[columnId]) {
col = 0;
row++;
}
m_wordLayout[columnId]->addWidget(addBtn, row, col, Qt::AlignCenter);
updatePanelSize(columnId);
}
//------------------------------------------------------------
void EasyInputArea::onRemoveWord(const QString& word) {
int a = -1;
int index;
for (int i = 0; i < WORD_COLUMN_AMOUNT; i++) {
index = m_wordList[i].indexOf(word);
if (index >= 0) {
a = i;
break;
}
}
if (a < 0 || a >= WORD_COLUMN_AMOUNT) return;
// delete button
int row = indexToRow(index, a);
int col = indexToCol(index, a);
WordButton* wordButton = qobject_cast<WordButton*>(
m_wordLayout[a]->itemAtPosition(row, col)->widget());
if (!wordButton) return;
bool ret = true;
ret = ret && disconnect(wordButton, SIGNAL(clicked(const QString&)), this,
SIGNAL(wordClicked(const QString&)));
ret = ret && disconnect(wordButton, SIGNAL(removeWord(const QString&)), this,
SLOT(onRemoveWord(const QString&)));
assert(ret);
m_wordLayout[a]->removeWidget(wordButton);
wordButton->deleteLater();
// move the following buttons
for (int i = index + 1; i <= m_wordList[a].count(); i++) {
int row = indexToRow(i, a);
int col = indexToCol(i, a);
QWidget* button = m_wordLayout[a]->itemAtPosition(row, col)->widget();
col--;
if (col < 0) {
row--;
col = areaColCount[a] - 1;
}
m_wordLayout[a]->addWidget(button, row, col, Qt::AlignCenter);
}
// remove word from the list
m_wordList[a].removeAt(index);
updatePanelSize(a);
}
//------------------------------------------------------------
StyleNameEditor::StyleNameEditor(QWidget* parent)
: QDialog(parent), m_paletteHandle(0) {
setWindowTitle(tr("Name Editor"));
m_styleName = new QLineEdit(this);
m_okButton = new QPushButton(tr("OK"), this);
m_cancelButton = new QPushButton(tr("Cancel"), this);
m_applyButton = new QPushButton(tr("Apply"), this);
m_styleName = new QLineEdit(this);
m_okButton = new QPushButton(tr("OK"), this);
m_cancelButton = new QPushButton(tr("Cancel"), this);
m_applyButton = new QPushButton(tr("Apply and Next"), this);
EasyInputArea* easyInputArea = new EasyInputArea(this);
m_styleName->setEnabled(false);
m_okButton->setEnabled(false);
@ -29,20 +339,20 @@ StyleNameEditor::StyleNameEditor(QWidget *parent)
m_styleName->setObjectName("LargeSizedText");
QVBoxLayout *mainLayout = new QVBoxLayout();
QVBoxLayout* mainLayout = new QVBoxLayout();
mainLayout->setMargin(10);
mainLayout->setSpacing(5);
{
QHBoxLayout *inputLayout = new QHBoxLayout();
QHBoxLayout* inputLayout = new QHBoxLayout();
inputLayout->setMargin(0);
inputLayout->setSpacing(3);
{
inputLayout->addWidget(new QLabel(tr("Style Name"), this), 0);
inputLayout->addWidget(m_styleName, 1);
}
mainLayout->addLayout(inputLayout);
mainLayout->addLayout(inputLayout, 0);
QHBoxLayout *buttonLayout = new QHBoxLayout();
QHBoxLayout* buttonLayout = new QHBoxLayout();
buttonLayout->setMargin(0);
buttonLayout->setSpacing(3);
{
@ -50,19 +360,32 @@ StyleNameEditor::StyleNameEditor(QWidget *parent)
buttonLayout->addWidget(m_applyButton);
buttonLayout->addWidget(m_cancelButton);
}
mainLayout->addLayout(buttonLayout);
mainLayout->addLayout(buttonLayout, 0);
mainLayout->addSpacing(5);
mainLayout->addWidget(new QLabel(tr("Easy Inputs"), this), 0,
Qt::AlignLeft);
mainLayout->addWidget(easyInputArea, 1);
}
setLayout(mainLayout);
setGeometry(640, 512, 420, 80);
resize(420, 300);
connect(m_okButton, SIGNAL(pressed()), this, SLOT(onOkPressed()));
connect(m_cancelButton, SIGNAL(pressed()), this, SLOT(onCancelPressed()));
connect(m_applyButton, SIGNAL(pressed()), this, SLOT(onApplyPressed()));
bool ret = true;
ret =
ret && connect(m_okButton, SIGNAL(pressed()), this, SLOT(onOkPressed()));
ret = ret && connect(m_cancelButton, SIGNAL(pressed()), this,
SLOT(onCancelPressed()));
ret = ret &&
connect(m_applyButton, SIGNAL(pressed()), this, SLOT(onApplyPressed()));
ret = ret && connect(easyInputArea, SIGNAL(wordClicked(const QString&)), this,
SLOT(onWordClicked(const QString&)));
assert(ret);
}
//-------
void StyleNameEditor::setPaletteHandle(TPaletteHandle *ph) {
void StyleNameEditor::setPaletteHandle(TPaletteHandle* ph) {
m_paletteHandle = ph;
connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
SLOT(onStyleSwitched()));
@ -74,7 +397,7 @@ void StyleNameEditor::setPaletteHandle(TPaletteHandle *ph) {
}
//-------
void StyleNameEditor::showEvent(QShowEvent *e) {
void StyleNameEditor::showEvent(QShowEvent* e) {
if (m_paletteHandle) {
disconnect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
SLOT(onStyleSwitched()));
@ -90,7 +413,7 @@ void StyleNameEditor::showEvent(QShowEvent *e) {
}
//-------disconnection
void StyleNameEditor::hideEvent(QHideEvent *e) {
void StyleNameEditor::hideEvent(QHideEvent* e) {
disconnect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
SLOT(onStyleSwitched()));
disconnect(m_paletteHandle, SIGNAL(paletteSwitched()), this,
@ -109,10 +432,13 @@ void StyleNameEditor::onStyleSwitched() {
setWindowTitle(tr("Name Editor: # %1").arg(styleId));
}
//-------
void StyleNameEditor::onOkPressed() {
onApplyPressed();
close();
}
//-------
void StyleNameEditor::onApplyPressed() {
if (!m_paletteHandle || !m_paletteHandle->getStyle()) return;
if (m_styleName->text() == "") return;
@ -120,12 +446,42 @@ void StyleNameEditor::onApplyPressed() {
std::wstring newName = m_styleName->text().toStdWString();
PaletteCmd::renamePaletteStyle(m_paletteHandle, newName);
// move the current style to the next
TPalette* palette = m_paletteHandle->getPalette();
int currentIndex = m_paletteHandle->getStyleIndex();
TPalette::Page* page = palette->getStylePage(currentIndex);
int indexInPage = page->search(currentIndex);
// If indexInPage is at the end of the page, then move to the top of the next
// page
if (indexInPage == page->getStyleCount() - 1) {
int pageIndex = page->getIndex();
// if the current page is the last one, then move to the first page
while (1) {
pageIndex++;
if (pageIndex == palette->getPageCount()) pageIndex = 0;
page = palette->getPage(pageIndex);
if (page->getStyleCount() > 0) break;
}
currentIndex = page->getStyleId(0);
} else
currentIndex = page->getStyleId(indexInPage + 1);
// change the current index
m_paletteHandle->setStyleIndex(currentIndex);
}
//-------
void StyleNameEditor::onCancelPressed() { close(); }
//-------
// focus when the mouse enters
void StyleNameEditor::enterEvent(QEvent *e) {
void StyleNameEditor::enterEvent(QEvent* e) {
activateWindow();
m_styleName->setFocus();
}
//-------
void StyleNameEditor::onWordClicked(const QString& word) {
m_styleName->insert(word);
}

View file

@ -304,5 +304,6 @@
<file>Resources/switchport_on.png</file>
<file>Resources/switchport_off.png</file>
<file>Resources/switchport_over.png</file>
<file>Resources/plus.png</file>
</qresource>
</RCC>