insilmaril@421: #include "branchpropwindow.h" insilmaril@421: insilmaril@440: #include insilmaril@440: insilmaril@421: #include "frameobj.h" insilmaril@462: #include "settings.h" insilmaril@421: insilmaril@462: extern Settings settings; insilmaril@487: extern QString vymName; insilmaril@487: insilmaril@421: insilmaril@480: BranchPropertyWindow::BranchPropertyWindow (QWidget *parent): QDialog (parent) insilmaril@421: { insilmaril@421: ui.setupUi (this); insilmaril@421: insilmaril@487: setCaption(vymName +" - " +tr ("Property Editor","Window caption")); insilmaril@487: insilmaril@421: branch=NULL; insilmaril@421: mapEditor=NULL; insilmaril@421: insilmaril@440: ui.tabWidget->setEnabled(false); insilmaril@440: insilmaril@440: penColor=QColor (Qt::black); insilmaril@440: brushColor=QColor (Qt::black); insilmaril@440: QPixmap pix( 16,16); insilmaril@440: pix.fill (penColor); insilmaril@440: ui.framePenColorButton->setPixmap (pix); insilmaril@440: ui.frameBrushColorButton->setPixmap (pix); insilmaril@480: insilmaril@672: // Create Model and View to hold attributes insilmaril@672: attributeModel = new QStandardItemModel (1,3,this); insilmaril@672: attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name")); insilmaril@672: attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value")); insilmaril@672: attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type")); insilmaril@672: ui.attributeTableView->setModel (attributeModel); insilmaril@672: insilmaril@480: insilmaril@480: // Load Settings insilmaril@480: resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize()); insilmaril@480: move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint()); insilmaril@480: insilmaril@480: if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool()) insilmaril@480: show(); insilmaril@480: else insilmaril@480: hide(); insilmaril@480: insilmaril@462: } insilmaril@440: insilmaril@462: BranchPropertyWindow::~BranchPropertyWindow () insilmaril@462: { insilmaril@480: settings.setValue( "/satellite/propertywindow/geometry/size", size() ); insilmaril@480: settings.setValue( "/satellite/propertywindow/geometry/pos", pos() ); insilmaril@530: settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() ); insilmaril@421: } insilmaril@421: insilmaril@421: void BranchPropertyWindow::setBranch (BranchObj *bo) insilmaril@421: { insilmaril@462: disconnectSignals(); insilmaril@421: branch=bo; insilmaril@440: if (bo) insilmaril@440: { insilmaril@440: ui.tabWidget->setEnabled (true); insilmaril@421: insilmaril@440: // Frame insilmaril@462: FrameObj::FrameType t=branch->getFrameType(); insilmaril@462: if (t==FrameObj::NoFrame) insilmaril@440: { insilmaril@440: ui.frameTypeCombo->setCurrentIndex (0); insilmaril@440: penColor=Qt::white; insilmaril@440: brushColor=Qt::white; insilmaril@440: ui.colorGroupBox->setEnabled (false); insilmaril@462: ui.framePaddingSpinBox->setEnabled (false); insilmaril@462: ui.frameWidthSpinBox->setEnabled (false); insilmaril@480: ui.framePaddingLabel->setEnabled (false); insilmaril@480: ui.frameBorderLabel->setEnabled (false); insilmaril@440: } else insilmaril@440: { insilmaril@440: penColor=bo->getFramePenColor(); insilmaril@440: brushColor=bo->getFrameBrushColor(); insilmaril@440: QPixmap pix( 16,16); insilmaril@440: pix.fill (penColor); insilmaril@480: ui.framePenColorButton->setPixmap (pix); insilmaril@440: pix.fill (brushColor); insilmaril@440: ui.frameBrushColorButton->setPixmap (pix); insilmaril@440: ui.colorGroupBox->setEnabled (true); insilmaril@462: ui.framePaddingSpinBox->setEnabled (true); insilmaril@462: ui.framePaddingSpinBox->setValue (bo->getFramePadding()); insilmaril@462: ui.frameWidthSpinBox->setEnabled (true); insilmaril@462: ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth()); insilmaril@480: ui.framePaddingLabel->setEnabled (true); insilmaril@480: ui.frameBorderLabel->setEnabled (true); insilmaril@440: insilmaril@440: switch (t) insilmaril@440: { insilmaril@462: case FrameObj::Rectangle: insilmaril@440: ui.frameTypeCombo->setCurrentIndex (1); insilmaril@440: break; insilmaril@462: case FrameObj::Ellipse: insilmaril@440: ui.frameTypeCombo->setCurrentIndex (2); insilmaril@440: break; insilmaril@440: default: insilmaril@440: break; insilmaril@440: } insilmaril@440: } insilmaril@440: insilmaril@440: // Link insilmaril@440: if (branch->getHideLinkUnselected()) insilmaril@440: ui.hideLinkIfUnselected->setCheckState (Qt::Checked); insilmaril@440: else insilmaril@440: ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked); insilmaril@462: insilmaril@462: // Layout insilmaril@462: if (branch->getIncludeImagesVer()) insilmaril@462: ui.incImgVer->setCheckState (Qt::Checked); insilmaril@462: else insilmaril@462: ui.incImgVer->setCheckState (Qt::Unchecked); insilmaril@462: if (branch->getIncludeImagesHor()) insilmaril@462: ui.incImgHor->setCheckState (Qt::Checked); insilmaril@462: else insilmaril@462: ui.incImgHor->setCheckState (Qt::Unchecked); insilmaril@462: insilmaril@672: // Attributes insilmaril@672: attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex()); insilmaril@672: insilmaril@672: // FIXME some samples for testing insilmaril@672: QStringList attrTypes=mapEditor->attributeTable()->getTypes(); insilmaril@672: for (int i=0; iinsertRow (i,QModelIndex ()); insilmaril@672: attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i)); insilmaril@672: attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i); insilmaril@672: attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i)); insilmaril@672: } insilmaril@672: insilmaril@672: insilmaril@672: ui.attributeTableView->resizeColumnsToContents(); insilmaril@672: insilmaril@672: // Initialize Delegate insilmaril@672: delegate.setAttributeTable (mapEditor->attributeTable()); insilmaril@672: ui.attributeTableView->setItemDelegate (&delegate); insilmaril@672: insilmaril@672: insilmaril@462: // Finally activate signals insilmaril@462: connectSignals(); insilmaril@440: } else insilmaril@421: { insilmaril@440: ui.tabWidget->setEnabled (false); insilmaril@421: } insilmaril@421: } insilmaril@421: insilmaril@421: void BranchPropertyWindow::setMapEditor (MapEditor *me) insilmaril@421: { insilmaril@440: mapEditor=me; insilmaril@440: if (mapEditor) insilmaril@440: setBranch (mapEditor->getSelectedBranch() ); insilmaril@440: else insilmaril@440: ui.tabWidget->setEnabled (false); insilmaril@440: insilmaril@421: } insilmaril@421: insilmaril@421: void BranchPropertyWindow::frameTypeChanged (int i) insilmaril@421: { insilmaril@421: if (mapEditor) insilmaril@480: { insilmaril@421: switch (i) insilmaril@421: { insilmaril@462: case 0: mapEditor->setFrameType (FrameObj::NoFrame); break; insilmaril@672: case 1: insilmaril@672: mapEditor->setFrameType (FrameObj::Rectangle); insilmaril@672: break; insilmaril@672: case 2: insilmaril@672: mapEditor->setFrameType (FrameObj::Ellipse); insilmaril@672: mapEditor->setFramePadding (5); insilmaril@672: break; insilmaril@421: } insilmaril@480: setBranch (branch); insilmaril@480: } insilmaril@421: } insilmaril@421: insilmaril@440: void BranchPropertyWindow::framePenColorClicked() insilmaril@440: { insilmaril@440: if (mapEditor) insilmaril@440: { insilmaril@440: QColor col = QColorDialog::getColor( penColor, this ); insilmaril@440: if ( col.isValid() ) insilmaril@440: { insilmaril@440: penColor=col; insilmaril@440: mapEditor->setFramePenColor (penColor); insilmaril@440: } insilmaril@440: } insilmaril@440: } insilmaril@440: insilmaril@440: void BranchPropertyWindow::frameBrushColorClicked() insilmaril@440: { insilmaril@440: if (mapEditor) insilmaril@440: { insilmaril@440: QColor col = QColorDialog::getColor( brushColor, this ); insilmaril@440: if ( col.isValid() ) insilmaril@440: { insilmaril@440: brushColor=col; insilmaril@440: mapEditor->setFrameBrushColor (brushColor); insilmaril@440: } insilmaril@440: } insilmaril@440: } insilmaril@440: insilmaril@462: void BranchPropertyWindow::framePaddingChanged(int i) insilmaril@462: { insilmaril@462: if (mapEditor) mapEditor->setFramePadding (i); insilmaril@462: } insilmaril@462: insilmaril@462: void BranchPropertyWindow::frameBorderWidthChanged(int i) insilmaril@462: { insilmaril@462: if (mapEditor) mapEditor->setFrameBorderWidth(i); insilmaril@462: } insilmaril@462: insilmaril@421: void BranchPropertyWindow::linkHideUnselectedChanged (int i) insilmaril@421: { insilmaril@421: if (!branch) return; insilmaril@462: mapEditor->setHideLinkUnselected(i); insilmaril@421: } insilmaril@421: insilmaril@462: void BranchPropertyWindow::incImgVerChanged (int i) insilmaril@462: { insilmaril@462: if (mapEditor) mapEditor->setIncludeImagesVer (i); insilmaril@462: } insilmaril@462: insilmaril@462: void BranchPropertyWindow::incImgHorChanged (int i) insilmaril@462: { insilmaril@462: if (mapEditor) mapEditor->setIncludeImagesHor (i); insilmaril@462: } insilmaril@462: insilmaril@480: void BranchPropertyWindow::closeEvent( QCloseEvent* ce ) insilmaril@480: { insilmaril@480: ce->accept(); // can be reopened with show() insilmaril@480: hide(); insilmaril@480: emit (windowClosed() ); insilmaril@480: return; insilmaril@480: } insilmaril@480: insilmaril@672: void BranchPropertyWindow::addAttributeClicked() insilmaril@672: { insilmaril@672: // Add empty line for adding attributes insilmaril@672: attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ()); insilmaril@672: attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new"); insilmaril@672: attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined"); insilmaril@672: insilmaril@672: // Select attribute from list insilmaril@672: ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() )); insilmaril@672: ui.attributeTableView->resizeColumnsToContents(); insilmaril@672: insilmaril@672: // QString attname=attributeModel->in insilmaril@672: // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), ); insilmaril@672: insilmaril@672: insilmaril@672: insilmaril@672: ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() )); insilmaril@672: insilmaril@672: } insilmaril@672: insilmaril@672: void BranchPropertyWindow::deleteAttributeClicked() insilmaril@672: { insilmaril@672: cout << "BPW::delete\n"; insilmaril@672: } insilmaril@480: insilmaril@462: void BranchPropertyWindow::connectSignals() insilmaril@462: { insilmaril@462: // Frame insilmaril@462: connect ( insilmaril@462: ui.framePenColorButton, SIGNAL (clicked()), insilmaril@462: this, SLOT (framePenColorClicked())); insilmaril@462: connect ( insilmaril@462: ui.framePaddingSpinBox, SIGNAL (valueChanged( int)), insilmaril@462: this, SLOT (framePaddingChanged (int))); insilmaril@462: connect ( insilmaril@462: ui.frameWidthSpinBox, SIGNAL (valueChanged( int)), insilmaril@462: this, SLOT (frameBorderWidthChanged (int))); insilmaril@462: connect ( insilmaril@462: ui.frameBrushColorButton, SIGNAL (clicked()), insilmaril@462: this, SLOT (frameBrushColorClicked())); insilmaril@462: connect ( insilmaril@462: ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)), insilmaril@462: this, SLOT (frameTypeChanged (int))); insilmaril@462: insilmaril@462: insilmaril@462: // Link insilmaril@462: connect ( insilmaril@462: ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)), insilmaril@462: this, SLOT (linkHideUnselectedChanged (int))); insilmaril@462: insilmaril@462: // Layout insilmaril@462: connect ( insilmaril@462: ui.incImgVer, SIGNAL (stateChanged( int)), insilmaril@462: this, SLOT (incImgVerChanged (int))); insilmaril@462: connect ( insilmaril@462: ui.incImgHor, SIGNAL (stateChanged( int)), insilmaril@462: this, SLOT (incImgHorChanged (int))); insilmaril@672: insilmaril@672: // Attributes insilmaril@672: connect ( insilmaril@672: ui.addAttributeButton, SIGNAL (clicked()), insilmaril@672: this, SLOT (addAttributeClicked())); insilmaril@672: connect ( insilmaril@672: ui.deleteAttributeButton, SIGNAL (clicked()), insilmaril@672: this, SLOT (deleteAttributeClicked())); insilmaril@462: } insilmaril@462: insilmaril@462: insilmaril@462: void BranchPropertyWindow::disconnectSignals() insilmaril@462: { insilmaril@480: // Frame insilmaril@462: disconnect ( ui.frameTypeCombo, 0,0,0); insilmaril@462: disconnect ( ui.framePenColorButton, 0,0,0); insilmaril@462: disconnect ( ui.framePaddingSpinBox, 0,0,0); insilmaril@462: disconnect ( ui.frameWidthSpinBox, 0,0,0); insilmaril@462: disconnect ( ui.frameBrushColorButton, 0,0,0); insilmaril@462: insilmaril@462: // Link insilmaril@462: disconnect ( ui.hideLinkIfUnselected, 0,0,0); insilmaril@462: insilmaril@462: // Layout insilmaril@462: disconnect ( ui.incImgVer, 0,0,0); insilmaril@462: disconnect ( ui.incImgHor, 0,0,0); insilmaril@672: insilmaril@672: // Attributes insilmaril@672: disconnect ( ui.addAttributeButton, 0,0,0); insilmaril@672: disconnect ( ui.deleteAttributeButton, 0,0,0); insilmaril@462: } insilmaril@462: insilmaril@462: