File indexing completed on 2024-05-05 05:46:19
0001 /*************************************************************************** 0002 * Copyright (C) 2006 David Saxton <david@bluehaze.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 ***************************************************************************/ 0009 0010 #include "itemeditor.h" 0011 #include "cnitem.h" 0012 #include "cnitemgroup.h" 0013 #include "component.h" 0014 #include "componentmodelwidget.h" 0015 #include "katemdi.h" 0016 #include "orientationwidget.h" 0017 #include "propertyeditor.h" 0018 0019 #include <KLocalizedString> 0020 0021 #include <QHBoxLayout> 0022 #include <QLabel> 0023 #include <QPushButton> 0024 0025 #include <cassert> 0026 0027 #include <ktechlab_debug.h> 0028 0029 ItemEditor *ItemEditor::m_pSelf = nullptr; 0030 0031 ItemEditor *ItemEditor::self(KateMDI::ToolView *parent) 0032 { 0033 if (!m_pSelf) { 0034 assert(parent); 0035 m_pSelf = new ItemEditor(parent); 0036 } 0037 return m_pSelf; 0038 } 0039 0040 ItemEditor::ItemEditor(KateMDI::ToolView *parent) 0041 : QWidget(static_cast<QWidget *>(parent)) 0042 { 0043 setObjectName("Item Editor"); 0044 setWhatsThis(i18n("This allows editing of advanced properties of the selected item(s). Right click on the picture of the item to set the orientation.")); 0045 0046 if (parent->layout()) { 0047 parent->layout()->addWidget(this); 0048 qCDebug(KTL_LOG) << " added item selector to parent's layout " << parent; 0049 } else { 0050 qCWarning(KTL_LOG) << " unexpected null layout on parent " << parent; 0051 } 0052 0053 QVBoxLayout *vlayout = new QVBoxLayout(this /*, 0, 6 */); 0054 vlayout->setMargin(0); 0055 vlayout->setSpacing(6); 0056 0057 // BEGIN Create Name Label 0058 m_pNameLabel = new QLabel(/* this, */ ""); 0059 m_pNameLabel->setBuddy(this); 0060 m_pNameLabel->setTextFormat(Qt::RichText); 0061 0062 QFont font; 0063 font.setBold(true); 0064 if (font.pointSize() != 0) 0065 font.setPointSize(int(font.pointSize() * 1.4)); 0066 m_pNameLabel->setFont(font); 0067 // END Create Name Label 0068 0069 m_pPropertyEditor = new PropertyEditor(this); 0070 m_pPropertyEditor->setWhatsThis( 0071 i18n("<p>Shows properties associated with the currently selected item(s).<br/>Select a property to change its value. If multiple items are selected with different values then the property will appear greyed out, use \"Merge " 0072 "Properties\" to make them the same.<br/>Select \"Defaults\" to set all properties to their default values")); 0073 0074 m_pComponentModelWidget = new ComponentModelWidget(this); 0075 0076 vlayout->addWidget(m_pNameLabel); 0077 vlayout->addWidget(m_pPropertyEditor, 3); 0078 vlayout->addWidget(m_pComponentModelWidget, 5); 0079 0080 // Orientation widget stuff 0081 QHBoxLayout *h2Layout = new QHBoxLayout(/* vlayout , 6 */); 0082 vlayout->addLayout(h2Layout); 0083 h2Layout->setMargin(6); 0084 h2Layout->addItem(new QSpacerItem(1, 1)); 0085 m_pOrientationWidget = new OrientationWidget(this); 0086 h2Layout->addWidget(m_pOrientationWidget); 0087 m_pOrientationWidget->setWhatsThis(i18n("Change the orientation of the selected item by selecting the appropriate button")); 0088 h2Layout->addItem(new QSpacerItem(1, 1)); 0089 0090 slotClear(); 0091 } 0092 0093 ItemEditor::~ItemEditor() 0094 { 0095 } 0096 0097 void ItemEditor::slotClear() 0098 { 0099 m_pPropertyEditor->setRowCount(0); 0100 m_pComponentModelWidget->reset(); 0101 m_pOrientationWidget->slotClear(); 0102 updateNameLabel(nullptr); 0103 } 0104 0105 void ItemEditor::slotMultipleSelected() 0106 { 0107 slotClear(); 0108 m_pNameLabel->setText(i18n("Multiple Items")); 0109 } 0110 0111 void ItemEditor::slotUpdate(ItemGroup *itemGroup) 0112 { 0113 if (!itemGroup) { 0114 slotClear(); 0115 return; 0116 } 0117 0118 m_pPropertyEditor->create(itemGroup); 0119 updateNameLabel(itemGroup->activeItem()); 0120 0121 m_pOrientationWidget->slotUpdate(dynamic_cast<CNItemGroup *>(itemGroup)); 0122 } 0123 0124 void ItemEditor::itemGroupUpdated(ItemGroup *itemGroup) 0125 { 0126 m_pPropertyEditor->updateDefaultsButton(); 0127 m_pOrientationWidget->slotUpdate(dynamic_cast<CNItemGroup *>(itemGroup)); 0128 } 0129 0130 void ItemEditor::slotUpdate(Item *item) 0131 { 0132 m_pComponentModelWidget->init(dynamic_cast<Component *>(item)); 0133 } 0134 0135 void ItemEditor::updateNameLabel(Item *item) 0136 { 0137 if (item) 0138 m_pNameLabel->setText(item->name()); 0139 0140 else 0141 m_pNameLabel->setText(i18n("No Item Selected")); 0142 } 0143 0144 #include "moc_itemeditor.cpp"