itemeditor.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2004 by David Saxton                               *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "cnitem.h"
00012 #include "cnitemgroup.h"
00013 #include "itemeditor.h"
00014 #include "orientationwidget.h"
00015 #include "propertieslistview.h"
00016 
00017 #include <klocale.h>
00018 #include <kstandarddirs.h>
00019 
00020 #include <qlayout.h>
00021 #include <qlabel.h>
00022 #include <qpushbutton.h>
00023 #include <qwhatsthis.h>
00024 
00025 #include <cassert>
00026 
00027 ItemEditor * ItemEditor::m_pSelf = 0;
00028 
00029 ItemEditor * ItemEditor::self( KateMDI::ToolView * parent )
00030 {
00031         if (!m_pSelf)
00032         {
00033                 assert(parent);
00034                 m_pSelf = new ItemEditor(parent);
00035         }
00036         return m_pSelf;
00037 }
00038 
00039 
00040 ItemEditor::ItemEditor( KateMDI::ToolView * parent )
00041         : QWidget( (QWidget*)parent, "Item Editor" )
00042 {
00043         QWhatsThis::add( this, i18n("This allows editing of advanced properties of the selected item(s). Right click on the picture of the item to set the orientation.") );
00044         
00045         QVBoxLayout *vlayout = new QVBoxLayout( this, 0, 6 );
00046 
00047         m_nameLbl = new QLabel( this, "" );
00048         vlayout->addWidget(m_nameLbl);
00049         vlayout->addSpacing(8);
00050 
00051         propList = new PropertiesListView(this);
00052         vlayout->addWidget(propList);
00053         QWhatsThis::add(propList,i18n("<qt>Shows properties associated with the currently selected item(s).<p>Select a property to change its value. If multiple items are selected with different values then the property will appear greyed out, use ""Merge Properties"" to make them the same.<p>Select ""Defaults to set all properties to their default values""")); 
00054         
00055         QHBoxLayout *h1Layout = new QHBoxLayout( vlayout, 4 );
00056         QSpacerItem *spacer1 = new QSpacerItem( 1, 1 );
00057         h1Layout->addItem(spacer1);
00058         
00059         m_defaultsBtn = new QPushButton( i18n("Defaults"), this);
00060         m_defaultsBtn->setEnabled(false);
00061         connect(m_defaultsBtn,SIGNAL(clicked()),propList,SLOT(slotSetDefaults()));
00062         h1Layout->addWidget(m_defaultsBtn);
00063         
00064         m_mergeBtn = new QPushButton( i18n("Merge properties"), this );
00065         m_mergeBtn->setEnabled(false);
00066         connect(m_mergeBtn,SIGNAL(clicked()),this,SLOT(mergeProperties()));
00067         h1Layout->addWidget(m_mergeBtn);
00068         
00069         // Orientation widget stuff
00070         QHBoxLayout *h2Layout = new QHBoxLayout( vlayout, 6 );
00071         QSpacerItem *spacer2 = new QSpacerItem( 1, 1 );
00072         h2Layout->addItem(spacer2);
00073         m_orientationWidget = new OrientationWidget(this);
00074         h2Layout->addWidget(m_orientationWidget);
00075         QWhatsThis::add(m_orientationWidget,i18n("Change the orientation of the selected item by selecting the appropriate button"));
00076         QSpacerItem *spacer3 = new QSpacerItem( 1, 1 );
00077         h2Layout->addItem(spacer3);
00078         
00079         slotClear();
00080 }
00081 
00082 
00083 ItemEditor::~ItemEditor()
00084 {
00085 }
00086 
00087 
00088 void ItemEditor::mergeProperties()
00089 {
00090         propList->slotMergeProperties();
00091         m_mergeBtn->setEnabled(false);
00092 }
00093 
00094 
00095 void ItemEditor::slotClear()
00096 {
00097         propList->slotClear();
00098         m_orientationWidget->slotClear();
00099         m_defaultsBtn->setEnabled(false);
00100         m_mergeBtn->setEnabled(false);
00101         updateNameLabel(0);
00102 }
00103 
00104 
00105 void ItemEditor::slotMultipleSelected()
00106 {
00107         slotClear();
00108         m_nameLbl->setText( i18n("<h2>Multiple Items</h2>") );
00109 }
00110 
00111 
00112 void ItemEditor::slotUpdate( ItemGroup *itemGroup )
00113 {
00114         if (!itemGroup) {
00115                 slotClear();
00116                 return;
00117         }
00118         
00119         updateMergeDefaults(itemGroup);
00120         propList->slotCreate(itemGroup);
00121         updateNameLabel(itemGroup->activeItem());
00122 }
00123 
00124 
00125 void ItemEditor::updateMergeDefaults( ItemGroup *itemGroup )
00126 {
00127         if (!itemGroup)
00128         {
00129                 m_defaultsBtn->setEnabled(false);
00130                 m_mergeBtn->setEnabled(false);
00131                 return;
00132         }
00133         
00134         m_mergeBtn->setEnabled( !itemGroup->itemsHaveSameData() );
00135         m_defaultsBtn->setEnabled( !itemGroup->itemsHaveDefaultData() );
00136         propList->slotUpdate(itemGroup);
00137 }
00138 
00139 
00140 void ItemEditor::slotUpdate( CNItem *item )
00141 {
00142         m_orientationWidget->slotUpdate(item);
00143 }
00144 
00145 
00146 void ItemEditor::updateNameLabel( Item *item )
00147 {
00148         if (item) {
00149                 m_nameLbl->setText( "<h2>" + item->name() + "</h2>" );
00150         } else {
00151                 m_nameLbl->setText( i18n("<h2>No Item Selected</h2>") );
00152         }
00153 }
00154 
00155 
00156 #include "itemeditor.moc"

Generated on Tue May 8 17:05:30 2007 for KTechLab by  doxygen 1.5.1