Implemented copy, cut and paste frame
[dashstudio.git] / src / components / timeline / framestable.cpp
blob90dc3612cfd19955f2b1675de56b0af58da2d9b9
1 /***************************************************************************
2 * Copyright (C) 2005 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "framestable.h"
23 #include <QPainter>
24 #include <QPaintEvent>
25 #include <QItemSelectionModel>
26 #include <QPainterPath>
27 #include <QScrollBar>
28 #include <QHeaderView>
29 #include <QMenu>
30 #include <QInputDialog>
31 #include <QApplication>
32 #include <QClipboard>
34 #include <dcore/debug.h>
35 #include <dcore/algorithm.h>
37 #include "tlruler.h"
39 namespace Dash {
40 namespace Component {
42 ////////// FramesTableItemDelegate ///////////
44 class FramesTableItemDelegate : public QAbstractItemDelegate
46 public:
47 FramesTableItemDelegate(QObject * parent = 0 );
48 ~FramesTableItemDelegate();
49 virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
50 virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
53 /**
56 FramesTableItemDelegate::FramesTableItemDelegate(QObject * parent) : QAbstractItemDelegate(parent)
60 FramesTableItemDelegate::~FramesTableItemDelegate()
66 void FramesTableItemDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
68 Q_ASSERT(index.isValid());
70 FramesTable *table = qobject_cast<FramesTable *>(index.model()->parent());
71 FramesTableItem *item = dynamic_cast<FramesTableItem *>(table->itemFromIndex(index));
73 QVariant value;
74 QStyleOptionViewItem opt = option;
76 // draw the background color
77 value = index.data( Qt::BackgroundColorRole );
79 if (value.isValid())
81 painter->save();
83 bool sound = table->isSoundLayer(index.row());
85 if( !sound )
87 painter->fillRect(option.rect, value.value<QColor>() );
89 painter->restore();
91 else
93 painter->save();
95 bool sound = table->isSoundLayer(index.row());
96 painter->setPen(QPen(Qt::lightGray, 1));
97 if( !sound )
99 if ( index.column() % 5 == 0 )
101 painter->setBrush(Qt::lightGray);
102 painter->drawRect(option.rect ); //FIXME: user paleta de colores
104 else
106 painter->setBrush(Qt::white);
107 painter->drawRect(option.rect);//FIXME: user paleta de color
110 else
112 painter->fillRect(option.rect, Qt::white);
115 painter->restore();
118 // Draw attributes
120 int offset = option.rect.width() - 4;
122 if ( item && index.isValid() )
124 if(item->isUsed() )
126 painter->save();
127 painter->setBrush(Qt::black);
129 if( !item->isSound() )
131 QColor color = Qt::white; //FIXME: user paleta de color
132 if ( item->inGroupPosition() == FramesTableItem::Begin )
134 painter->fillRect(option.rect, color);
135 painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
136 painter->drawEllipse(option.rect.left()+2, option.rect.bottom() - (offset+2), offset, offset);
138 else if ( item->inGroupPosition() == FramesTableItem::End )
140 painter->fillRect(option.rect, color );
141 painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
143 else if( item->inGroupPosition() == FramesTableItem::Intermediate )
145 painter->fillRect(option.rect, color );
147 else
149 painter->drawEllipse(option.rect.left()+2, option.rect.bottom() - (offset+2), offset, offset);
152 else
154 painter->setPen(QPen(Qt::blue, 1));
156 int y = option.rect.center().y();
157 int xi = option.rect.x();
158 int xf = option.rect.width();
160 painter->drawLine(QPoint(xi, y) , QPoint(xf, y));
163 painter->restore();
166 if ( item->isLocked() )
168 painter->save();
169 painter->setBrush(Qt::red);
171 painter->drawEllipse(option.rect.left()+2, option.rect.bottom() - (offset+2), offset, offset);
173 painter->restore();
177 // Selection!
178 if (option.showDecorationSelected && (option.state & QStyle::State_Selected))
180 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
182 painter->save();
183 painter->setPen(QPen(option.palette.brush(cg, QPalette::Highlight), 2));
185 QRectF rectSelection = option.rect.adjusted(1,1,-1,-1);
186 painter->drawRect(rectSelection);
187 painter->restore();
190 painter->save();
191 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
192 painter->setPen(QPen(option.palette.brush(cg, QPalette::Foreground), 1)),
194 painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
195 painter->drawLine(option.rect.topLeft(), option.rect.topRight());
196 painter->restore();
199 QSize FramesTableItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
201 Q_ASSERT(index.isValid());
202 const QAbstractItemModel *model = index.model();
203 Q_ASSERT(model);
205 QVariant value = model->data(index, Qt::FontRole);
206 QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
207 QString text = model->data(index, Qt::DisplayRole).toString();
208 QRect pixmapRect;
209 if (model->data(index, Qt::DecorationRole).isValid())
210 pixmapRect = QRect(0, 0, option.decorationSize.width(),
211 option.decorationSize.height());
213 QFontMetrics fontMetrics(fnt);
215 return (pixmapRect).size();
219 ////////// FramesTableItem ////////
221 FramesTableItem::FramesTableItem()
225 FramesTableItem::~FramesTableItem()
230 bool FramesTableItem::isUsed()
232 return data(IsUsed).toBool();
235 bool FramesTableItem::isLocked()
237 return data(IsLocked).toBool();
240 bool FramesTableItem::isVisible()
242 return data(IsVisible).toBool();
245 bool FramesTableItem::isSound()
247 QVariant data = this->data(IsSound);
249 if( data.canConvert<bool>() )
251 return data.toBool();
253 return false;
256 bool FramesTableItem::isClone()
258 QVariant data = this->data(IsClone);
260 if( data.canConvert<bool>() )
262 return data.toBool();
264 return false;
267 FramesTableItem::InGroupPositionType FramesTableItem::inGroupPosition()
269 QVariant data = this->data(InGroupPosition);
271 if( data.canConvert<int>() )
273 return InGroupPositionType(data.toInt());
275 return None;
279 //// FramesTable
281 struct FramesTable::Private
283 struct LayerItem
285 LayerItem() : lastItem(-1), sound(false) {};
286 int lastItem;
287 bool sound;
291 void swapItem( QTableWidgetItem *it, QTableWidgetItem *nextIt )
293 QVariant data = it->data(FramesTableItem::IsUsed);
295 it->setData(FramesTableItem::IsUsed, nextIt->data(FramesTableItem::IsUsed).toBool() );
296 nextIt->setData(FramesTableItem::IsUsed, data);
298 data = it->data(FramesTableItem::IsLocked);
299 it->setData(FramesTableItem::IsLocked, nextIt->data(FramesTableItem::IsLocked).toBool());
300 nextIt->setData(FramesTableItem::IsLocked, data);
303 data = it->data(FramesTableItem::IsVisible);
304 it->setData(FramesTableItem::IsVisible, nextIt->data(FramesTableItem::IsVisible).toBool());
305 nextIt->setData(FramesTableItem::IsVisible, data);
307 data = it->data(FramesTableItem::IsSound);
308 it->setData(FramesTableItem::IsSound, nextIt->data(FramesTableItem::IsSound).toBool());
309 nextIt->setData(FramesTableItem::IsSound, data);
311 data = it->data(FramesTableItem::InGroupPosition);
312 it->setData(FramesTableItem::InGroupPosition, nextIt->data(FramesTableItem::InGroupPosition));
313 nextIt->setData(FramesTableItem::InGroupPosition, data);
317 int groupSize(FramesTable *table, int layer, int beginFrame)
319 QTableWidgetItem *item = table->item(layer, beginFrame);
321 if( ! item )
323 return 0;
326 int count = 0;
328 dfDebug << "begin Frame " << beginFrame << " type " << item->data(FramesTableItem::InGroupPosition).toInt();
330 if(item->data(FramesTableItem::InGroupPosition).toInt() == FramesTableItem::Begin)
332 while(item && item->data(FramesTableItem::InGroupPosition).toInt() != FramesTableItem::End)
334 count++;
335 item = table->item(layer, beginFrame+count);
339 return count+1;
342 int rectWidth, rectHeight;
343 QList<LayerItem> layers;
344 TLRuler *ruler;
346 enum Action {
347 InsertFrame = 0,
348 RemoveFrame,
349 ToggleLockFrame,
350 ToggleFrameVisibility,
351 ExpandFrame,
352 CopyFrame,
353 PasteFrame,
354 CutFrame
360 * @~spanish
361 * Contructor
363 FramesTable::FramesTable(QWidget *parent) : QTableWidget(0, 100, parent), d(new Private)
365 d->ruler = new TLRuler;
366 setup();
370 * @~spanish
371 * Destructor
373 FramesTable::~FramesTable()
375 delete d;
379 * @internal
381 void FramesTable::setup()
383 setItemDelegate( new FramesTableItemDelegate(this) );
385 setSelectionBehavior(QAbstractItemView::SelectItems);
386 setSelectionMode (QAbstractItemView::SingleSelection);
388 setHorizontalHeader(d->ruler);
390 connect(d->ruler, SIGNAL(logicalSectionSelected( int )), this, SLOT(emitFrameSelected( int )));
391 // connect(this, SIGNAL(currentItemChanged( QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(emitFrameSelected(QTableWidgetItem *, QTableWidgetItem *)));
392 verticalHeader()->hide();
395 connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(onItemSelectionChanged()));
397 connect( this, SIGNAL(cellDoubleClicked ( int , int )), this, SLOT(onCellDoubleClicked(int, int)));
399 setItemSize( 10, 25 );
401 horizontalHeader()->setResizeMode(QHeaderView::Custom);
402 verticalHeader()->setResizeMode(QHeaderView::Custom);
405 setSelectionMode(QAbstractItemView::ContiguousSelection);
406 setShowGrid(false);
410 * @internal
412 void FramesTable::emitFrameSelected(int col)
414 selectColumn(col);
416 FramesTableItem *item = dynamic_cast<FramesTableItem *>(this->item(currentRow(), col));
418 if( item )
420 if( item->isUsed())
422 emit frameSelected(visualRow(this->row(item)), visualColumn(this->column(item)));
428 * @internal
430 void FramesTable::onItemSelectionChanged()
432 FramesTableItem *item = dynamic_cast<FramesTableItem *>(currentItem());
433 if( item )
435 if( item->isUsed())
437 emit frameSelected(visualRow(this->row(item)), visualColumn(this->column(item)));
440 else
442 emit layerSelected(visualRow(currentRow()));
447 * @~spanish
448 * Función sobrecargada para la implementación del menú contextual.
450 void FramesTable::mousePressEvent ( QMouseEvent * event )
453 QTableWidget::mousePressEvent(event);
454 if(event->buttons() == Qt::RightButton )
456 QMenu *menu = new QMenu(tr("Frames"), this);
458 FramesTableItem *item = dynamic_cast<FramesTableItem *>(currentItem());
460 menu->addAction( tr("Insert frame"))->setData(Private::InsertFrame);
462 if(item)
464 if( item->isUsed())
466 menu->addAction( tr("Remove frame"))->setData(Private::RemoveFrame);
467 menu->addAction( tr("Expand this frame"))->setData(Private::ExpandFrame);
468 menu->addSeparator();
469 menu->addAction(tr("Copy frame"))->setData(Private::CopyFrame);
471 menu->addAction(tr("Cut frame"))->setData(Private::CutFrame);
473 else
475 menu->addSeparator();
479 if(const QMimeData *mimeData = QApplication::clipboard()->mimeData())
481 if(mimeData->hasFormat("yamf-frame"))
483 menu->addAction( tr("Paste frame"))->setData(Private::PasteFrame);
484 menu->addSeparator();
488 if(item)
490 if( item->isLocked())
492 menu->addAction( tr("Unlock this frame"))->setData(Private::ToggleLockFrame);
494 else
496 menu->addAction( tr("Lock this frame"))->setData(Private::ToggleLockFrame);
499 if(item->isVisible())
501 menu->addAction( tr("Hide this frame"))->setData(Private::ToggleFrameVisibility);
503 else
505 menu->addAction( tr("Show this frame"))->setData(Private::ToggleFrameVisibility);
509 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(onMenuActionTriggered(QAction * )));
511 menu->exec( event->globalPos() );
516 * @internal
518 void FramesTable::onCellDoubleClicked(int row, int column)
520 row = visualRow(row);
521 if( lastFrameByLayer(row)+1 == column )
523 emit requestInsertFrame(row, column);
528 * @internal
530 void FramesTable::onMenuActionTriggered(QAction * action)
532 int layerPos = visualRow(currentRow());
533 int framePos = visualColumn(currentColumn());
535 switch(action->data().toInt())
537 case Private::InsertFrame:
539 FramesTableItem *item = dynamic_cast<FramesTableItem *>(currentItem());
540 if(item)
542 if(item->isUsed())
544 emit requestInsertFrame(layerPos, framePos+1);
547 else
549 emit requestInsertFrame(layerPos, framePos);
553 break;
554 case Private::RemoveFrame:
556 emit requestRemoveFrame(layerPos, framePos);
558 break;
559 case Private::CopyFrame:
561 emit requestCopyFrame(layerPos, framePos);
563 break;
564 case Private::PasteFrame:
566 emit requestPasteFrame(layerPos, framePos);
568 break;
569 case Private::CutFrame:
571 emit requestCutFrame(layerPos, framePos);
573 break;
574 case Private::ToggleLockFrame:
576 FramesTableItem *item = dynamic_cast<FramesTableItem *>(currentItem());
577 if(item)
579 emit requestLockFrame(layerPos, framePos, !item->isLocked());
582 break;
583 case Private::ToggleFrameVisibility:
585 FramesTableItem *item = dynamic_cast<FramesTableItem *>(currentItem());
586 if(item)
588 emit requestChangeFrameVisibility(layerPos, framePos, !item->isVisible());
591 break;
592 case Private::ExpandFrame:
594 FramesTableItem *item = dynamic_cast<FramesTableItem *>(currentItem());
595 if(item)
597 bool ok = false;
598 int size = QInputDialog::getInteger ( 0, tr("Expand frame"), tr("number of frames to enlarge this frame?"), 1, 1, 2000, 1, &ok);
599 if(ok)
601 emit requestExpandFrame(layerPos, framePos, size);
605 break;
610 * @~spanish
611 * Cambia el tamaño de los frames.
613 void FramesTable::setItemSize(int w, int h)
615 d->rectHeight = h;
616 d->rectWidth = w;
618 fixSize();
622 * @~spanish
623 * Extiende el largo de un frame, para permitir la realimentación gráfica de la expansión del tiempo de un frame.
625 void FramesTable::expandFrame( int layerPosition, int position, int size )
627 groupFrames( layerPosition, position, position+size);
629 for(int i = position; i < position+size; i++)
631 QTableWidgetItem *item = this->item(layerPosition, i);
632 item->setData(FramesTableItem::IsClone, true);
638 * @~spanish
639 * Agrupa los frames de la posición @p from a la @p to del layer, para permitir la realimentación gráfica de la agrupación de un conjunto de frames.
641 void FramesTable::groupFrames( int layerPosition, int from, int to )
643 for(int i = from+1; i <= to; i++)
645 QTableWidgetItem *item = this->item(layerPosition, i);
647 if(item)
649 item->setData(FramesTableItem::InGroupPosition, QVariant( FramesTableItem::Intermediate));
653 QTableWidgetItem *begin = this->item(layerPosition, from);
655 if(begin)
657 begin->setData(FramesTableItem::InGroupPosition ,QVariant(FramesTableItem::Begin));
660 QTableWidgetItem *end = this->item(layerPosition, to);
662 if(end)
664 QTableWidgetItem *nextEnd = this->item(layerPosition, to+1);
666 if(nextEnd)
668 if(nextEnd->data(FramesTableItem::InGroupPosition).toInt() != FramesTableItem::None || nextEnd->data(FramesTableItem::InGroupPosition).toInt() != FramesTableItem::Begin)
670 end->setData(FramesTableItem::InGroupPosition, QVariant(FramesTableItem::Intermediate));
671 viewport()->update();
672 return;
675 end->setData(FramesTableItem::InGroupPosition, QVariant(FramesTableItem::End));
678 viewport()->update();
682 * @~spanish
683 * Destruye el grupo de frames que esta en la posición @p position del layer @p layerPosition, para permitir la realimentación gráfica de la destrucción de un conjunto de frames.
685 void FramesTable::destroyGroupFrames(int layerPosition, int position, int size)
687 for(int i = position; i <= position+size; i++)
689 QTableWidgetItem *item = this->item(layerPosition, i);
691 if(item)
693 item->setData(FramesTableItem::InGroupPosition, QVariant( FramesTableItem::None));
694 item->setData(FramesTableItem::IsClone, false);
700 * @~spanish
701 * Retorna verdadero si el layer en la posición @p row es de sonido, falso de lo contrario.
703 bool FramesTable::isSoundLayer(int row)
705 if( row < 0 && row >= d->layers.count() )
706 return false;
708 return d->layers[row].sound;
712 * @~spanish
713 * Inserta un layer en la posición @p pos con el nombre @p name, permitiendo la realimentación gráfica de la inserción de un layer.
715 void FramesTable::insertLayer(int pos, const QString &name)
717 Q_UNUSED(name);
718 insertRow( pos );
720 Private::LayerItem layer;
721 layer.sound = false;
722 d->layers.insert(pos, layer);
724 fixSize();
728 * @~spanish
729 * Inserta un layer de sonido en la posicion @p pos con el nombre @p name. permitiendo la realimentación gráfica de la inserción de un layer de sonido.
731 void FramesTable::insertSoundLayer(int layerPos, const QString &name)
733 Q_UNUSED(name);
734 insertRow(layerPos);
736 Private::LayerItem layer;
737 layer.sound = true;
738 d->layers.insert(layerPos, layer);
740 fixSize();
744 * @~spanish
745 * Elimina el layer seleccionado actualmente, permitiendo la realimentación gráfica de la eliminación del layer actual.
747 void FramesTable::removeCurrentLayer()
749 int pos = verticalHeader()->logicalIndex(currentRow());
750 removeLayer(pos);
754 * @~spanish
755 * Elimina el layer de la posición @p pos, permitiendo la realimentación gráfica de la eliminación de un layer.
757 void FramesTable::removeLayer(int pos)
759 pos = verticalHeader()->logicalIndex(pos);
760 removeRow( pos );
761 d->layers.removeAt(pos);
765 * @~spanish
766 * Mueve el layer de la posición @p position a la posición @p newPosition.
768 void FramesTable::moveLayer(int position, int newPosition)
770 if ( position < 0 || position >= rowCount() || newPosition < 0 || newPosition >= rowCount() ) return;
772 blockSignals(true);
774 verticalHeader()->moveSection(position, newPosition);
776 blockSignals(false);
780 * @~spanish
781 * Obtiene la posición del ultimo frame del layer que esta en la posición @p layerPos.
783 int FramesTable::lastFrameByLayer(int layerPos)
785 int pos = verticalHeader()->logicalIndex(layerPos);
786 if ( pos < 0 || pos > d->layers.count() )
788 return -1;
790 return d->layers[pos].lastItem;
793 // FRAMES
796 * @~spanish
797 * Añade un frame al layer de la posicion @p layerPos, con el nombre @p name.
799 void FramesTable::addFrame(int layerPos, const QString &name)
801 Q_UNUSED(name);
802 if ( layerPos < 0 || layerPos >= d->layers.count() ) return;
804 insertFrame(layerPos, lastFrameByLayer(verticalHeader()->logicalIndex(layerPos))+1, name) ;
808 * @~spanish
809 * Inserta un frame en la posición @p framePos del layer @p layerPos, con el nombre @p name.
811 void FramesTable::insertFrame(int layerPos, int framePos, const QString &name)
813 Q_UNUSED(name);
815 if ( layerPos < 0 || layerPos >= d->layers.count() ) return;
817 layerPos = verticalHeader()->logicalIndex(layerPos);
819 d->layers[layerPos].lastItem++;
821 int position = framePos;
823 if(!d->layers[layerPos].sound)
825 position = d->layers[layerPos].lastItem;
828 setAttribute( layerPos, position, FramesTableItem::IsUsed, true);
829 setAttribute( layerPos, position, FramesTableItem::IsVisible, true);
830 setAttribute( layerPos, position, FramesTableItem::IsSound, d->layers[layerPos].sound);
831 item( layerPos, position)->setData(FramesTableItem::InGroupPosition, FramesTableItem::None);
833 if(!d->layers[layerPos].sound)
835 moveFrame(layerPos, position, framePos);
837 if ( d->layers[layerPos].lastItem >= columnCount()-1 )
839 setColumnCount( d->layers[layerPos].lastItem+50 );
840 fixSize();
843 viewport()->update();
847 * @~spanish
848 * Selecciona el frame, representado por el ítem @p item.
850 void FramesTable::setCurrentFrame(FramesTableItem *item)
852 setCurrentItem(item);
856 * @~spanish
857 * Selecciona el layer de la posición @p layerPos.
859 void FramesTable::setCurrentLayer(int layerPos)
861 setCurrentItem(item(verticalHeader()->logicalIndex(layerPos), 0));
865 * @~spanish
866 * Selecciona el frame la posición @p index del layer actual.
868 void FramesTable::selectFrame(int index)
870 setCurrentItem( item( currentRow(), index ) );
874 * @~spanish
875 * Remueve el frame que esta en la posición @p position del layer @p layerPos.
877 void FramesTable::removeFrame(int layerPos, int position)
879 if ( layerPos < 0 || layerPos >= d->layers.count() )
881 return;
884 QTableWidgetItem *it = this->item(layerPos, position);
886 moveFrame(layerPos, position, d->layers[layerPos].lastItem);
888 QTableWidgetItem *toRemove = takeItem(layerPos, d->layers[layerPos].lastItem);
890 int type = toRemove->data(FramesTableItem::InGroupPosition).toInt();
892 if(type == FramesTableItem::Begin)
894 it = item(layerPos, position);
896 if(it)
898 if(it->data(FramesTableItem::InGroupPosition).toInt() == FramesTableItem::Intermediate)
900 it->setData(FramesTableItem::InGroupPosition, toRemove->data(FramesTableItem::InGroupPosition));
902 else if(it->data(FramesTableItem::InGroupPosition).toInt() == FramesTableItem::End)
904 it->setData(FramesTableItem::InGroupPosition, FramesTableItem::None);
905 it->setData(FramesTableItem::IsClone, false);
909 else if(toRemove->data(FramesTableItem::InGroupPosition).toInt() == FramesTableItem::End)
911 it = item(layerPos, position);
912 if(it)
914 if(it->data(FramesTableItem::InGroupPosition).toInt() == FramesTableItem::Begin)
916 it->setData(FramesTableItem::InGroupPosition, FramesTableItem::None);
922 delete toRemove;
923 toRemove = 0;
925 d->layers[layerPos].lastItem--;
927 viewport()->update( visualRect(indexFromItem(item(layerPos, position) )) );
928 viewport()->update();
932 * @~spanish
933 * Mueve el frame de la posición @p from a la posición @p to dentro del layer @p layerPos.
935 void FramesTable::moveFrame(int layerPos, int from, int to)
937 if(from == to)
939 return;
942 layerPos = verticalHeader()->logicalIndex(layerPos);
944 if(to > from)
946 int fromSize = d->groupSize(this, layerPos, from);
947 int toSize = d->groupSize(this, layerPos, to);
949 for(int i = 0; i < fromSize; i++)
951 for(int index = from; index < to+toSize-1; index++ )
953 QTableWidgetItem *it = item(layerPos, index);
954 QTableWidgetItem *nextIt = item(layerPos, index+1);
955 if(nextIt)
957 d->swapItem(it, nextIt);
962 else
964 int fromSize = d->groupSize(this, layerPos, from);
965 int toSize = d->groupSize(this, layerPos, to);
966 Q_UNUSED(toSize);
968 for(int i = 0; i < fromSize; i++)
970 for(int index = from+i; index > to+i; index-- )
972 QTableWidgetItem *it = item(layerPos, index);
973 QTableWidgetItem *nextIt = item(layerPos, index-1);
974 if(nextIt)
976 d->swapItem(it, nextIt);
982 viewport()->update();
986 * @spanish
987 * Actualiza el estado de bloqueo del frame que esta en la posición @p postín del layer @p layerPos al valor de @p locked.
989 void FramesTable::lockFrame(int layerPos, int position, bool locked)
991 if ( layerPos < 0 || layerPos >= d->layers.count() )
993 return;
996 layerPos = verticalHeader()->logicalIndex(layerPos);
998 setAttribute( layerPos, position, FramesTableItem::IsLocked, locked );
1000 viewport()->update();
1004 * @~spanish
1005 * Actualiza el estado de visibilidad del frame que esta en la posición @p position del layer @p layerPosition a el valor de @p isVisible.
1007 void FramesTable::setFrameVisibility(int layerPosition, int position, bool isVisible)
1009 if ( layerPosition < 0 || layerPosition >= d->layers.count() )
1011 return;
1014 layerPosition = verticalHeader()->logicalIndex(layerPosition);
1016 setAttribute( layerPosition, position, FramesTableItem::IsVisible, isVisible );
1018 viewport()->update();
1022 * @~spanish
1023 * Modifica el estado de un frame.
1025 void FramesTable::setAttribute(int row, int col, FramesTableItem::Attributes att, bool value)
1027 QTableWidgetItem *item = this->item(row, col);
1029 if( !item )
1031 item = new FramesTableItem;
1032 setItem(row, col, item);
1035 item->setData(att, value);
1039 * @~spanish
1040 * Arregla los tamaños de los frames mostrados en la tabla.
1042 void FramesTable::fixSize()
1044 for(int column = 0; column < columnCount(); column++)
1046 horizontalHeader()->resizeSection(column, d->rectWidth);
1048 for( int row = 0; row < rowCount(); row++)
1050 verticalHeader()->resizeSection(row, d->rectHeight);