Allow Changing Parent of Column from XSheet (#68)

This commit is contained in:
Jeremy Bullock 2020-07-01 22:55:41 -06:00 committed by GitHub
parent a57d5ece0a
commit 5136b21737
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 141 additions and 37 deletions

View file

@ -344,10 +344,19 @@ void ChangeObjectWidget::mouseMoveEvent(QMouseEvent *event) {
//-----------------------------------------------------------------------------
void ChangeObjectWidget::wheelEvent(QWheelEvent *event) {
QListWidget::wheelEvent(event);
event->accept();
}
//-----------------------------------------------------------------------------
void ChangeObjectWidget::focusOutEvent(QFocusEvent *e) {
if (!isVisible()) return;
hide();
parentWidget()->update();
if (parentWidget()) {
parentWidget()->update();
}
}
//-----------------------------------------------------------------------------
@ -397,18 +406,35 @@ void ChangeObjectParent::refresh() {
QString indexStr(std::to_string(id.getIndex() + 1).c_str());
QString newText;
if (id == parentId) {
if (parentId.isPegbar())
if (parentId.isTable())
text = QString("Table");
else if (parentId.isPegbar())
text = QString("Peg ") + indexStr;
else if (parentId.isColumn())
text = QString("Col ") + indexStr;
else if (parentId.isColumn()) {
text = QString("Col ") + indexStr;
QString tempText = newText;
std::string name = tree->getStageObject(i)->getName();
if (name != tempText.replace(" ", "").toStdString()) {
text += " (" + QString::fromStdString(name) + " )";
}
}
}
if (id == currentObjectId) continue;
if (id.isTable()) {
newText = QString("Table");
pegbarList.append(newText);
}
if (id.isPegbar()) {
newText = QString("Peg ") + indexStr;
pegbarList.append(newText);
}
if (id.isColumn() && (!xsh->isColumnEmpty(index) || index < 2)) {
newText = QString("Col ") + indexStr;
newText = QString("Col ") + indexStr;
QString tempText = newText;
std::string name = tree->getStageObject(i)->getName();
if (name.length() > 0 && name != tempText.replace(" ", "").toStdString()) {
newText += " (" + QString::fromStdString(name) + " )";
}
columnList.append(newText);
}
if (newText.length() > theLongestTxt.length()) theLongestTxt = newText;
@ -428,7 +454,8 @@ void ChangeObjectParent::refresh() {
// set font size in pixel
font.setPixelSize(XSHEET_FONT_PX_SIZE);
m_width = QFontMetrics(font).width(theLongestTxt) + 2;
m_width = QFontMetrics(font).width(theLongestTxt) + 22;
std::string strText = text.toStdString();
selectCurrent(text);
}
@ -443,22 +470,34 @@ void ChangeObjectParent::onTextChanged(const QString &text) {
}
bool isPegbar = false;
if (text.startsWith("Peg")) isPegbar = true;
bool isTable = false;
if (text == "Table") isTable = true;
QString number = text;
number.remove(0, 4);
// Remove names from the index
int spaceIndex = number.indexOf(" ");
if (spaceIndex > -1) number.remove(spaceIndex, 1000);
int index = number.toInt() - 1;
if (index < 0) {
if (!isTable && index < 0) {
hide();
return;
}
TXsheet *xsh = m_xsheetHandle->getXsheet();
TStageObjectId currentObjectId = m_objectHandle->getObjectId();
TStageObjectId currentParentId =
xsh->getStageObject(currentObjectId)->getParent();
TStageObjectId newStageObjectId;
if (isPegbar)
newStageObjectId = TStageObjectId::PegbarId(index);
else if (isTable)
newStageObjectId = TStageObjectId::TableId;
else
newStageObjectId = TStageObjectId::ColumnId(index);
if (newStageObjectId == currentObjectId) return;
if (newStageObjectId == currentParentId) return;
TStageObject *stageObject =
m_xsheetHandle->getXsheet()->getStageObject(currentObjectId);
TStageObjectCmd::setParent(currentObjectId, newStageObjectId, "B",
@ -1086,6 +1125,30 @@ void ColumnArea::DrawHeader::drawPegbarName() const {
TStageObjectId columnId = m_viewer->getObjectId(col);
TStageObjectId parentId = xsh->getStageObjectParent(columnId);
std::string strName = xsh->getStageObject(parentId)->getName();
QString name = QString(parentId.toString().c_str());
if (strName.length() > 0 && parentId.toString() != strName) {
name = QString::fromStdString(strName);
}
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
fontName = "Arial";
#else
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
// set font size in pixel
font.setPixelSize(XSHEET_FONT_PX_SIZE);
int width = QFontMetrics(font).width(name);
while (width > o->rect(PredefinedRect::PEGBAR_NAME).width() - 20) {
name.remove(-1, 1000);
width = QFontMetrics(font).width(name);
}
// pegbar name
QRect pegbarnamerect = o->rect(PredefinedRect::PEGBAR_NAME).translated(orig);
@ -1099,8 +1162,7 @@ void ColumnArea::DrawHeader::drawPegbarName() const {
p.setPen(m_viewer->getTextColor());
p.drawText(pegbarnamerect.adjusted(3, 0, 0, 0),
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
QString(parentId.toString().c_str()));
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, name);
}
void ColumnArea::DrawHeader::drawParentHandleName() const {
@ -1118,15 +1180,16 @@ void ColumnArea::DrawHeader::drawParentHandleName() const {
TStageObjectId columnId = m_viewer->getObjectId(col);
TStageObjectId parentId = xsh->getStageObjectParent(columnId);
p.setPen(m_viewer->getVerticalLineColor());
p.drawRect(parenthandleRect.adjusted(2, 0, 0, 0));
p.setPen(m_viewer->getTextColor());
std::string handle = xsh->getStageObject(columnId)->getParentHandle();
if (handle[0] == 'H' && handle.length() > 1) handle = handle.substr(1);
if (parentId != TStageObjectId::TableId)
p.drawText(parenthandleRect,
Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine,
QString::fromStdString(handle));
// if (parentId != TStageObjectId::TableId)
p.drawText(parenthandleRect,
Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine,
QString::fromStdString(handle));
}
void ColumnArea::DrawHeader::drawFilterColor() const {
@ -1239,12 +1302,12 @@ ColumnArea::ColumnArea(XsheetViewer *parent, Qt::WFlags flags)
, m_soundColumnPopup(0) {
TXsheetHandle *xsheetHandle = TApp::instance()->getCurrentXsheet();
TObjectHandle *objectHandle = TApp::instance()->getCurrentObject();
m_changeObjectParent = new ChangeObjectParent(0);
m_changeObjectParent = new ChangeObjectParent(m_viewer);
m_changeObjectParent->setObjectHandle(objectHandle);
m_changeObjectParent->setXsheetHandle(xsheetHandle);
m_changeObjectParent->hide();
m_changeObjectHandle = new ChangeObjectHandle(0);
m_changeObjectHandle = new ChangeObjectHandle(m_viewer);
m_changeObjectHandle->setObjectHandle(objectHandle);
m_changeObjectHandle->setXsheetHandle(xsheetHandle);
m_changeObjectHandle->hide();
@ -2201,6 +2264,25 @@ void ColumnArea::mousePressEvent(QMouseEvent *event) {
event->button() == Qt::RightButton)
return;
if (o->rect(PredefinedRect::PEGBAR_NAME)
.adjusted(0, 0, -20, 0)
.contains(mouseInCell)) {
m_changeObjectParent->refresh();
m_changeObjectParent->show(
QPoint(o->rect(PredefinedRect::PARENT_HANDLE_NAME).bottomLeft() +
m_viewer->positionToXY(CellPosition(0, m_col)) +
QPoint(o->rect(PredefinedRect::CAMERA_CELL).width(), 4)));
return;
}
if (o->rect(PredefinedRect::PARENT_HANDLE_NAME).contains(mouseInCell)) {
m_changeObjectHandle->refresh();
m_changeObjectHandle->show(
QPoint(o->rect(PredefinedRect::PARENT_HANDLE_NAME).bottomLeft() +
m_viewer->positionToXY(CellPosition(0, m_col + 1)) +
QPoint(2, 0)));
return;
}
setDragTool(XsheetGUI::DragTool::makeColumnSelectionTool(m_viewer));
if (column) {
@ -2676,7 +2758,8 @@ void ColumnArea::contextMenuEvent(QContextMenuEvent *event) {
// setMask->setCheckable(true);
// setMask->setChecked(xsh->getColumn(col)->isMask());
// setMask->setToolTip(
// tr("Only Toonz Vector levels can be used as masks. \n Masks don't "
// tr("Only Toonz Vector levels can be used as masks. \n Masks don't
// "
// "show up in final renders."));
// bool ret = true;
// ret = ret &&

View file

@ -89,6 +89,7 @@ public:
protected:
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void focusOutEvent(QFocusEvent *e) override;
void focusInEvent(QFocusEvent *e) override {}
void selectCurrent(const QString &text);

View file

@ -3427,12 +3427,20 @@ void StyleEditor::onStyleChanged(bool isDragging) {
m_colorParameterSelector->setStyle(*m_editedStyle);
m_settingsPage->setStyle(m_editedStyle);
m_newColor->setStyle(*m_editedStyle);
TPixel32 color = m_editedStyle->getMainColor();
QString myColor = QString::number(color.r) + ", " + QString::number(color.g) +
", " + QString::number(color.b);
std::string myColorStr = myColor.toStdString();
QString styleSheet = "background-color: rgb(%1);";
m_fillColorWidget->setStyleSheet(styleSheet.arg(myColor));
int tag = m_editedStyle->getTagId();
if (tag == 4 || tag == 2000 || tag == 2800) {
m_fillColorWidget->hide();
} else {
m_fillColorWidget->show();
TPixel32 color = m_editedStyle->getMainColor();
QString myColor = QString::number(color.r) + ", " +
QString::number(color.g) + ", " +
QString::number(color.b);
std::string myColorStr = myColor.toStdString();
QString styleSheet = "background-color: rgb(%1);";
m_fillColorWidget->setStyleSheet(styleSheet.arg(myColor));
}
m_oldColor->setStyle(
*m_oldStyle); // This line is needed for proper undo behavior
}
@ -3530,13 +3538,19 @@ void StyleEditor::onColorChanged(const ColorModel &color, bool isDragging) {
}
m_newColor->setStyle(*m_editedStyle);
TPixel32 color = m_editedStyle->getMainColor();
QString myColor = QString::number(color.r) + ", " +
QString::number(color.g) + ", " +
QString::number(color.b);
std::string myColorStr = myColor.toStdString();
QString styleSheet = "background-color: rgb(%1);";
m_fillColorWidget->setStyleSheet(styleSheet.arg(myColor));
int tag = m_editedStyle->getTagId();
if (tag == 4 || tag == 2000 || tag == 2800) {
m_fillColorWidget->hide();
} else {
m_fillColorWidget->show();
TPixel32 color = m_editedStyle->getMainColor();
QString myColor = QString::number(color.r) + ", " +
QString::number(color.g) + ", " +
QString::number(color.b);
std::string myColorStr = myColor.toStdString();
QString styleSheet = "background-color: rgb(%1);";
m_fillColorWidget->setStyleSheet(styleSheet.arg(myColor));
}
m_colorParameterSelector->setStyle(*m_editedStyle);
if (m_autoButton->isChecked()) {
@ -3678,14 +3692,20 @@ bool StyleEditor::setStyle(TColorStyle *currentStyle) {
m_plainColorPage->setColor(*currentStyle, getColorParam());
m_oldColor->setStyle(*currentStyle);
m_newColor->setStyle(*currentStyle);
TPixel32 color = currentStyle->getMainColor();
QString myColor = QString::number(color.r) + ", " +
QString::number(color.g) + ", " +
QString::number(color.b);
std::string myColorStr = myColor.toStdString();
QString styleSheet = "background-color: rgb(%1);";
m_fillColorWidget->setStyleSheet(styleSheet.arg(myColor));
int tag = currentStyle->getTagId();
if (tag == 4 || tag == 2000 || tag == 2800) {
m_fillColorWidget->hide();
} else {
m_fillColorWidget->show();
TPixel32 color = currentStyle->getMainColor();
QString myColor = QString::number(color.r) + ", " +
QString::number(color.g) + ", " +
QString::number(color.b);
std::string myColorStr = myColor.toStdString();
QString styleSheet = "background-color: rgb(%1);";
m_fillColorWidget->setStyleSheet(styleSheet.arg(myColor));
}
setOldStyleToStyle(currentStyle);
}