File indexing completed on 2024-05-12 04:04:30
0001 /* 0002 Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu> 0003 Copyright 2010 Stefan Majewsky <majewsky@gmx.net> 0004 0005 This program is free software; you can redistribute it and/or modify 0006 it under the terms of the GNU General Public License as published by 0007 the Free Software Foundation; either version 2 of the License, or 0008 (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0018 */ 0019 0020 #include "editor.h" 0021 #include "itemfactory.h" 0022 0023 #include <QLabel> 0024 #include <QListWidget> 0025 #include <QHBoxLayout> 0026 #include <KLocalizedString> 0027 Editor::Editor(const Kolf::ItemFactory& factory, QWidget *parent) 0028 : QWidget(parent) 0029 , m_factory(factory) 0030 { 0031 config = nullptr; 0032 0033 hlayout = new QHBoxLayout(this); 0034 0035 QVBoxLayout *vlayout = new QVBoxLayout; 0036 hlayout->addLayout( vlayout ); 0037 vlayout->addWidget(new QLabel(i18n("Add object:"), this)); 0038 m_typeList = new QListWidget(this); 0039 vlayout->addWidget(m_typeList); 0040 hlayout->setStretchFactor(vlayout, 2); 0041 0042 //populate type list 0043 const auto knownTypes = factory.knownTypes(); 0044 for (const Kolf::ItemMetadata& metadata : knownTypes) { 0045 QListWidgetItem* item = new QListWidgetItem(metadata.name); 0046 item->setData(Qt::UserRole, metadata.identifier); 0047 m_typeList->addItem(item); 0048 } 0049 connect(m_typeList, &QListWidget::itemClicked, this, &Editor::listboxExecuted); 0050 } 0051 0052 void Editor::listboxExecuted(QListWidgetItem* item) 0053 { 0054 Q_EMIT addNewItem(item->data(Qt::UserRole).toString()); //data(UserRole) contains the type identifier 0055 } 0056 0057 void Editor::setItem(CanvasItem *item) 0058 { 0059 delete config; 0060 config = item->config(this); 0061 if (!config) 0062 return; 0063 config->ctorDone(); 0064 hlayout->addWidget(config); 0065 hlayout->setStretchFactor(config, 2); 0066 config->setFrameStyle(QFrame::Box | QFrame::Raised); 0067 config->setLineWidth(1); 0068 config->show(); 0069 connect(config, &Config::modified, this, &Editor::changed); 0070 } 0071 0072 #include "moc_editor.cpp"