Implemented copy, cut and paste frame
[dashstudio.git] / src / components / library / gctable.cpp
blob178be7904502105cfa55a2ac60a22e9c316c1d30
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 "gctable.h"
23 #include <QHeaderView>
25 #include <dgui/iconloader.h>
27 #include <yamf/model/library.h>
28 #include <yamf/model/libraryobject.h>
29 #include <QLineEdit>
31 GCTable::GCTable(QWidget *parent)
32 : QTreeWidget(parent), m_currentFolder(0)
34 setHeaderLabels(QStringList() << "" << "" );
35 header()->hide();
36 header()->setResizeMode(QHeaderView::ResizeToContents);
40 GCTable::~GCTable()
44 void GCTable::createFolder(const QString &name)
46 QTreeWidgetItem *newFolder = new QTreeWidgetItem(this);
48 if ( name.isNull() )
50 newFolder->setText(0, tr("New folder %1").arg( topLevelItemCount ()) );
52 else
54 newFolder->setText(0, name );
57 newFolder->setIcon(0, DGui::IconLoader::self()->load( "folder.svg" ));
58 m_currentFolder = newFolder;
60 setCurrentItem(m_currentFolder);
65 QTreeWidgetItem *GCTable::currentFolder()
67 return m_currentFolder;
70 void GCTable::setCurrentFolder(QTreeWidgetItem *cf)
72 if ( cf )
74 m_currentFolder = cf;
78 void GCTable::removeCurrentFolder()
80 if ( m_currentFolder )
82 int index = indexOfTopLevelItem(m_currentFolder) - 1;
84 delete m_currentFolder;
86 m_currentFolder = topLevelItem (index);
87 setCurrentItem(m_currentFolder);
91 void GCTable::commitData( QWidget * editor )
93 QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
94 QString symbol;
95 QTreeWidgetItem *item = currentItem ();
96 if(item)
98 symbol = item->text(0);
99 // QTreeWidget::commitData(0); // Don't rename
101 if(lineEdit)
103 emit requestRenameSymbol(symbol, lineEdit->text());
106 QTreeWidget::commitData(editor);