insilmaril@421: #include "branchpropwindow.h" insilmaril@421: insilmaril@440: #include insilmaril@440: insilmaril@779: #include "branchitem.h" 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@785: branchItem=NULL; insilmaril@721: model=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@785: // Create Model and View to hold attributes // FIXME-3 insilmaril@767: /* 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@767: */ 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@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@787: void BranchPropertyWindow::setItem (TreeItem *ti) insilmaril@421: { insilmaril@462: disconnectSignals(); insilmaril@787: if (!ti) insilmaril@787: ui.tabWidget->setEnabled (false); insilmaril@787: else if (ti->isBranchLikeType() ) insilmaril@440: { insilmaril@787: branchItem=(BranchItem*)ti; insilmaril@421: insilmaril@785: branch=(BranchObj*)(branchItem->getLMO()); insilmaril@787: if (branch) // FIXME-3 replace by branchItem later, when Frame is ported... insilmaril@440: { insilmaril@785: ui.tabWidget->setEnabled (true); insilmaril@787: for (int i=0; i<3;++i) insilmaril@787: ui.tabWidget->setTabEnabled (i,true); insilmaril@787: ui.tabWidget->setTabEnabled (3,false); insilmaril@440: insilmaril@785: // Frame insilmaril@785: FrameObj::FrameType t=branch->getFrameType(); insilmaril@785: if (t==FrameObj::NoFrame) insilmaril@440: { insilmaril@785: ui.frameTypeCombo->setCurrentIndex (0); insilmaril@785: penColor=Qt::white; insilmaril@785: brushColor=Qt::white; insilmaril@785: ui.colorGroupBox->setEnabled (false); insilmaril@785: ui.framePaddingSpinBox->setEnabled (false); insilmaril@785: ui.frameWidthSpinBox->setEnabled (false); insilmaril@785: ui.framePaddingLabel->setEnabled (false); insilmaril@785: ui.frameBorderLabel->setEnabled (false); insilmaril@785: } else insilmaril@785: { insilmaril@785: penColor=branch->getFramePenColor(); insilmaril@785: brushColor=branch->getFrameBrushColor(); insilmaril@785: QPixmap pix( 16,16); insilmaril@785: pix.fill (penColor); insilmaril@785: ui.framePenColorButton->setPixmap (pix); insilmaril@785: pix.fill (brushColor); insilmaril@785: ui.frameBrushColorButton->setPixmap (pix); insilmaril@785: ui.colorGroupBox->setEnabled (true); insilmaril@785: ui.framePaddingSpinBox->setEnabled (true); insilmaril@785: ui.framePaddingSpinBox->setValue (branch->getFramePadding()); insilmaril@785: ui.frameWidthSpinBox->setEnabled (true); insilmaril@785: ui.frameWidthSpinBox->setValue (branch->getFrameBorderWidth()); insilmaril@785: ui.framePaddingLabel->setEnabled (true); insilmaril@785: ui.frameBorderLabel->setEnabled (true); insilmaril@785: insilmaril@785: switch (t) insilmaril@785: { insilmaril@785: case FrameObj::Rectangle: insilmaril@785: ui.frameTypeCombo->setCurrentIndex (1); insilmaril@785: break; insilmaril@785: case FrameObj::Ellipse: insilmaril@785: ui.frameTypeCombo->setCurrentIndex (2); insilmaril@785: break; insilmaril@785: default: insilmaril@785: break; insilmaril@785: } insilmaril@785: } insilmaril@785: insilmaril@785: // Link insilmaril@785: if (branchItem->getHideLinkUnselected()) insilmaril@785: ui.hideLinkIfUnselected->setCheckState (Qt::Checked); insilmaril@785: else insilmaril@785: ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked); insilmaril@785: insilmaril@785: // Layout insilmaril@785: if (branchItem->getIncludeImagesVer()) insilmaril@785: ui.incImgVer->setCheckState (Qt::Checked); insilmaril@785: else insilmaril@785: ui.incImgVer->setCheckState (Qt::Unchecked); insilmaril@785: if (branchItem->getIncludeImagesHor()) insilmaril@785: ui.incImgHor->setCheckState (Qt::Checked); insilmaril@785: else insilmaril@785: ui.incImgHor->setCheckState (Qt::Unchecked); insilmaril@785: insilmaril@785: /* insilmaril@785: // Attributes insilmaril@785: attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex()); insilmaril@785: insilmaril@785: // FIXME-3 some samples for attribute testing insilmaril@785: QStringList attrTypes=mapEditor->attributeTable()->getTypes(); insilmaril@785: for (int i=0; iinsertRow (i,QModelIndex ()); insilmaril@785: attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i)); insilmaril@785: attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i); insilmaril@785: attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i)); insilmaril@440: } insilmaril@462: insilmaril@462: insilmaril@785: ui.attributeTableView->resizeColumnsToContents(); insilmaril@672: insilmaril@785: // Initialize Delegate insilmaril@785: delegate.setAttributeTable (mapEditor->attributeTable()); insilmaril@785: ui.attributeTableView->setItemDelegate (&delegate); insilmaril@785: */ insilmaril@672: insilmaril@785: // Finally activate signals insilmaril@785: connectSignals(); insilmaril@787: } // BranchItem insilmaril@787: } else if (ti->getType()==TreeItem::Attribute) insilmaril@787: { insilmaril@787: ui.tabWidget->setEnabled (true); insilmaril@787: for (int i=0; i<3;++i) insilmaril@787: ui.tabWidget->setTabEnabled (i,false); insilmaril@787: ui.tabWidget->setTabEnabled (3,true); insilmaril@440: } else insilmaril@421: { insilmaril@440: ui.tabWidget->setEnabled (false); insilmaril@421: } insilmaril@421: } insilmaril@421: insilmaril@721: void BranchPropertyWindow::setModel (VymModel *m) insilmaril@421: { insilmaril@721: model=m; insilmaril@721: if (model) insilmaril@787: setItem (model->getSelectedItem() ); 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@721: if (model) insilmaril@480: { insilmaril@421: switch (i) insilmaril@421: { insilmaril@721: case 0: model->setFrameType (FrameObj::NoFrame); break; insilmaril@672: case 1: insilmaril@721: model->setFrameType (FrameObj::Rectangle); insilmaril@672: break; insilmaril@672: case 2: insilmaril@721: model->setFrameType (FrameObj::Ellipse); insilmaril@721: model->setFramePadding (5); insilmaril@672: break; insilmaril@421: } insilmaril@787: setItem (branchItem); insilmaril@480: } insilmaril@421: } insilmaril@421: insilmaril@440: void BranchPropertyWindow::framePenColorClicked() insilmaril@440: { insilmaril@721: if (model) insilmaril@440: { insilmaril@440: QColor col = QColorDialog::getColor( penColor, this ); insilmaril@440: if ( col.isValid() ) insilmaril@440: { insilmaril@440: penColor=col; insilmaril@721: model->setFramePenColor (penColor); insilmaril@440: } insilmaril@440: } insilmaril@440: } insilmaril@440: insilmaril@440: void BranchPropertyWindow::frameBrushColorClicked() insilmaril@440: { insilmaril@721: if (model) insilmaril@440: { insilmaril@440: QColor col = QColorDialog::getColor( brushColor, this ); insilmaril@440: if ( col.isValid() ) insilmaril@440: { insilmaril@440: brushColor=col; insilmaril@721: model->setFrameBrushColor (brushColor); insilmaril@440: } insilmaril@440: } insilmaril@440: } insilmaril@440: insilmaril@462: void BranchPropertyWindow::framePaddingChanged(int i) insilmaril@462: { insilmaril@721: if (model) model->setFramePadding (i); insilmaril@462: } insilmaril@462: insilmaril@462: void BranchPropertyWindow::frameBorderWidthChanged(int i) insilmaril@462: { insilmaril@721: if (model) model->setFrameBorderWidth(i); insilmaril@462: } insilmaril@462: insilmaril@421: void BranchPropertyWindow::linkHideUnselectedChanged (int i) insilmaril@421: { insilmaril@785: if (!branchItem) return; insilmaril@721: model->setHideLinkUnselected(i); insilmaril@421: } insilmaril@421: insilmaril@462: void BranchPropertyWindow::incImgVerChanged (int i) insilmaril@462: { insilmaril@721: if (model) model->setIncludeImagesVer (i); insilmaril@462: } insilmaril@462: insilmaril@462: void BranchPropertyWindow::incImgHorChanged (int i) insilmaril@462: { insilmaril@721: if (model) model->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@767: /* 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@746: //FIXME-3 cout << "BPW::delete\n"; insilmaril@672: } insilmaril@767: */ 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@767: /* 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@767: */ 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@767: /* insilmaril@672: disconnect ( ui.addAttributeButton, 0,0,0); insilmaril@672: disconnect ( ui.deleteAttributeButton, 0,0,0); insilmaril@767: */ insilmaril@462: } insilmaril@462: insilmaril@462: