X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flayerwidget.cpp;h=9177b206594aa3979a986495f3e8a079d200e89d;hb=790c1a6d97f73f7457c7fad7e82fa29e5b6accd5;hp=9ac85a87379fab084125300448db2f32ccb2429a;hpb=a6e76b6a748a350bda067a99672f9dcca626d872;p=architektonas diff --git a/src/layerwidget.cpp b/src/layerwidget.cpp index 9ac85a8..9177b20 100644 --- a/src/layerwidget.cpp +++ b/src/layerwidget.cpp @@ -69,8 +69,10 @@ LayerWidget::LayerWidget(void): QWidget(), Global::numLayers = 1; Global::layerHidden.clear(); Global::layerLocked.clear(); + Global::layerName.clear(); Global::layerHidden.push_back(false); Global::layerLocked.push_back(false); + Global::layerName.push_back("Background"); } @@ -79,10 +81,33 @@ LayerWidget::~LayerWidget() } +void LayerWidget::Reload(void) +{ + list->clear(); + + for(int i=0; iinsertItem(0, qlwi); + list->setItemWidget(qlwi, liw); + + // Set up SIGNAL/SLOTs for this LayerItemWidget + connect(liw, SIGNAL(HideToggled(QListWidgetItem *, bool)), this, SLOT(HandleHideToggle(QListWidgetItem *, bool))); + connect(liw, SIGNAL(LockToggled(QListWidgetItem *, bool)), this, SLOT(HandleLockToggle(QListWidgetItem *, bool))); + } + + int layer = (Global::numLayers - Global::activeLayer) - 1; + list->setCurrentRow(layer, QItemSelectionModel::SelectCurrent); + SetButtonStates(); +} + + void LayerWidget::HandleLayerSelected(int currentRow) { -//printf("LayerWidget::HandleLayerSelected(): currentRow = %i\n", currentRow); -// emit(LayerSelected(currentRow)); + // If LayerWidget is empty, bail out + if (currentRow == -1) + return; // This is numbered opposite of how it's presented. In other words, the // bottom of the list is 0, and items above it count upwards. So like this: @@ -93,7 +118,7 @@ void LayerWidget::HandleLayerSelected(int currentRow) // // which is the opposite of the internal numbering. Global::activeLayer = (Global::numLayers - currentRow) - 1; -//printf("LayerWidget::HandleLayerSelected(): currentRow = %i, numLayers = %i, active = %i\n", currentRow, Global::numLayers, Global::activeLayer); + // Set button states to sane values SetButtonStates(); } @@ -114,7 +139,7 @@ void LayerWidget::HandleHideToggle(QListWidgetItem * qlwi, bool state) //printf("Item #%i, new hide state is %s\n", currentRow, (state ? "ON" : "off")); //printf("LayerWidget: New hide state of layer %i is %s.\n", layer, (state ? "ON" : "off")); // We do this last, because otherwise the Document would get the wrong state - emit(LayerToggled()); + emit LayerToggled(); } @@ -136,7 +161,8 @@ void LayerWidget::HandleDblClick(QListWidgetItem * /*qlwi*/) void LayerWidget::AddLayer(void) { - // We always stick the newest layer at the top of the list... + // We always stick the newest layer at the top of the list (visually, the + // top of the list is the end, the bottom is the beginning)... int count = list->count(); QString text = QString("Layer #%1").arg(count); QListWidgetItem * qlwi = new QListWidgetItem(); @@ -151,8 +177,9 @@ void LayerWidget::AddLayer(void) SetButtonStates(); // Fix up the global state - Global::layerHidden.insert(Global::layerHidden.begin(), false); - Global::layerLocked.insert(Global::layerLocked.begin(), false); + Global::layerHidden.push_back(false); + Global::layerLocked.push_back(false); + Global::layerName.push_back(text.toUtf8().data()); Global::numLayers++; } @@ -168,7 +195,7 @@ void LayerWidget::DeleteLayer(void) // HandleLayerSelected() to be fired off which causes the numbers to // be off. You have been warned! // Tell the DrawingView to delete this layer in its Container: - emit(LayerDeleted(Global::activeLayer)); + emit LayerDeleted(Global::activeLayer); int currentRow = list->currentRow(); QListWidgetItem * qlwi = list->currentItem(); @@ -181,6 +208,7 @@ void LayerWidget::DeleteLayer(void) int layer = (Global::numLayers - currentRow) - 1; Global::layerHidden.erase(Global::layerHidden.begin() + layer); Global::layerLocked.erase(Global::layerLocked.begin() + layer); + Global::layerName.erase(Global::layerName.begin() + layer); Global::numLayers--; // If we're deleting from the top of the list, we have to decrement the @@ -201,7 +229,13 @@ void LayerWidget::EditLayer(void) QString result = QInputDialog::getText(this, tr("Edit Layer Name"), tr("Layer Name:"), QLineEdit::Normal, s, &ok); if (ok && !result.isEmpty()) + { li->name->setText(result); + + int layer = (Global::numLayers - Global::activeLayer) - 1; + std::vector::iterator i = Global::layerName.begin() + layer; + (*i) = result.toUtf8().data(); + } } @@ -236,8 +270,11 @@ void LayerWidget::MoveLayerUp(void) old = Global::layerLocked[layer]; Global::layerLocked[layer] = Global::layerLocked[layer + 1]; Global::layerLocked[layer + 1] = old; + std::string oldStr = Global::layerName[layer]; + Global::layerName[layer] = Global::layerName[layer + 1]; + Global::layerName[layer + 1] = oldStr; // We also have to tell the document to shuffle its layers too - emit(LayersSwapped(layer, layer + 1)); + emit LayersSwapped(layer, layer + 1); } @@ -272,8 +309,11 @@ void LayerWidget::MoveLayerDown(void) old = Global::layerLocked[layer]; Global::layerLocked[layer] = Global::layerLocked[layer - 1]; Global::layerLocked[layer - 1] = old; + std::string oldStr = Global::layerName[layer]; + Global::layerName[layer] = Global::layerName[layer - 1]; + Global::layerName[layer - 1] = oldStr; // We also have to tell the document to shuffle its layers too - emit(LayersSwapped(layer, layer - 1)); + emit LayersSwapped(layer, layer - 1); }