21 #include <kedittoolbar_p.h>
25 #include <QtXml/QDomDocument>
26 #include <QtGui/QLayout>
27 #include <QtCore/QDir>
28 #include <QtCore/QFile>
29 #include <QHeaderView>
30 #include <QtGui/QToolButton>
31 #include <QtGui/QLabel>
32 #include <QtGui/QApplication>
33 #include <QtGui/QGridLayout>
34 #include <QtGui/QCheckBox>
51 #include <kdeversion.h>
60 #define SEPARATORSTRING i18n(separatorstring)
66 namespace KDEPrivate {
78 for( QDomElement elem = start; !elem.isNull(); elem = elem.nextSiblingElement() ) {
79 if (elem.tagName() == tagToolBar) {
80 if ( elem.attribute( attrNoEdit ) !=
"true" )
83 if (elem.tagName() != tagMenuBar)
94 enum XmlType {
Shell = 0, Part, Local, Merged };
97 : m_isModified(false),
100 m_actionCollection(collection)
106 foreach (
const QDomElement& element, m_barList) {
107 kDebug(240) <<
" ToolBar:" << toolBarText( element );
109 if ( m_actionCollection )
110 kDebug(240) <<
" " << m_actionCollection->actions().count() <<
"actions in the collection.";
112 kDebug(240) <<
" no action collection.";
114 QString xmlFile()
const {
return m_xmlFile; }
115 XmlType type()
const {
return m_type; }
117 void setDomDocument(
const QDomDocument& domDoc)
119 m_document = domDoc.cloneNode().toDocument();
123 QDomDocument& domDocument() {
return m_document; }
124 const QDomDocument& domDocument()
const {
return m_document; }
129 QString toolBarText(
const QDomElement& it )
const;
134 const ToolBarList& barList()
const {
return m_barList; }
139 QDomDocument m_document;
144 QString XmlData::toolBarText(
const QDomElement& it )
const
151 QByteArray txt( it.namedItem( tagText ).toElement().text().toUtf8() );
153 txt = it.namedItem( tagText2 ).toElement().text().toUtf8();
155 name = it.attribute( attrName );
161 if ( ( m_type == XmlData::Shell ) ||
162 ( m_type == XmlData::Part ) ) {
163 QString doc_name(m_document.documentElement().attribute( attrName ));
164 name +=
" <" + doc_name +
'>';
172 class ToolBarItem :
public QListWidgetItem
176 : QListWidgetItem(parent),
178 m_internalName(name),
179 m_statusText(statusText),
180 m_isSeparator(
false),
181 m_isTextAlongsideIconHidden(
false)
184 setFlags((flags() | Qt::ItemIsDragEnabled) & ~Qt::ItemIsDropEnabled);
187 void setInternalTag(
const QString &tag) { m_internalTag = tag; }
188 void setInternalName(
const QString &name) { m_internalName =
name; }
189 void setStatusText(
const QString &text) { m_statusText = text; }
190 void setSeparator(
bool sep) { m_isSeparator = sep; }
191 void setTextAlongsideIconHidden(
bool hidden) { m_isTextAlongsideIconHidden = hidden; }
192 QString internalTag()
const {
return m_internalTag; }
193 QString internalName()
const {
return m_internalName; }
194 QString statusText()
const {
return m_statusText; }
195 bool isSeparator()
const {
return m_isSeparator; }
196 bool isTextAlongsideIconHidden()
const {
return m_isTextAlongsideIconHidden; }
198 int index()
const {
return listWidget()->row(const_cast<ToolBarItem*>(
this)); }
205 bool m_isTextAlongsideIconHidden;
208 static QDataStream &
operator<< ( QDataStream & s,
const ToolBarItem & item ) {
209 s << item.internalTag();
210 s << item.internalName();
211 s << item.statusText();
212 s << item.isSeparator();
213 s << item.isTextAlongsideIconHidden();
216 static QDataStream &
operator>> ( QDataStream & s, ToolBarItem & item ) {
219 item.setInternalTag(internalTag);
222 item.setInternalName(internalName);
225 item.setStatusText(statusText);
228 item.setSeparator(sep);
231 item.setTextAlongsideIconHidden(hidden);
237 ToolBarListWidget::ToolBarListWidget(
QWidget *parent)
241 setDragDropMode(QAbstractItemView::DragDrop);
248 QMimeData* mimedata =
new QMimeData();
252 QDataStream stream(&data, QIODevice::WriteOnly);
254 ToolBarItem* item =
static_cast<ToolBarItem *
>(items.first());
258 mimedata->setData(
"application/x-kde-action-list", data);
259 mimedata->setData(
"application/x-kde-source-treewidget", m_activeList ?
"active" :
"inactive");
264 bool ToolBarListWidget::dropMimeData(
int index,
const QMimeData * mimeData, Qt::DropAction action)
267 const QByteArray data = mimeData->data("application/x-kde-action-list");
270 QDataStream stream(data);
271 const
bool sourceIsActiveList = mimeData->data("application/x-kde-source-treewidget") == "active";
272 ToolBarItem* item = new ToolBarItem(this);
274 emit dropped(this, index, item, sourceIsActiveList);
278 ToolBarItem* ToolBarListWidget::currentItem()
const
280 return static_cast<ToolBarItem*
>(QListWidget::currentItem());
284 IconTextEditDialog::IconTextEditDialog(
QWidget *parent)
287 setCaption(
i18n(
"Change Text"));
289 setDefaultButton(
Ok);
293 QGridLayout *layout =
new QGridLayout(mainWidget);
294 layout->setMargin(0);
297 m_lineEdit->setClearButtonShown(
true);
299 label->setBuddy(m_lineEdit);
300 layout->addWidget(label, 0, 0);
301 layout->addWidget(m_lineEdit, 0, 1);
303 m_cbHidden =
new QCheckBox(
i18n(
"&Hide text when toolbar shows text alongside icons"), mainWidget);
304 layout->addWidget(m_cbHidden, 1, 1);
306 connect(m_lineEdit, SIGNAL(textChanged(
QString)), SLOT(slotTextChanged(
QString)));
308 m_lineEdit->setFocus();
309 setMainWidget(mainWidget);
310 setFixedHeight(sizeHint().height());
313 void IconTextEditDialog::setIconText(
const QString &text)
315 m_lineEdit->setText(text);
318 QString IconTextEditDialog::iconText()
const
320 return m_lineEdit->text().trimmed();
323 void IconTextEditDialog::setTextAlongsideIconHidden(
bool hidden)
325 m_cbHidden->setChecked(hidden);
328 bool IconTextEditDialog::textAlongsideIconHidden()
const
330 return m_cbHidden->isChecked();
333 void IconTextEditDialog::slotTextChanged(
const QString &text)
336 enableButton(
Ok, !text.trimmed().isEmpty());
340 class KEditToolBarWidgetPrivate
350 KEditToolBarWidgetPrivate(KEditToolBarWidget* widget,
352 : m_collection( collection ),
355 m_loadedOnce( false )
357 m_componentData = cData;
360 m_kdialogProcess = 0;
363 const int iconSize = widget->style()->pixelMetric(QStyle::PM_SmallIconSize);
364 m_emptyIcon = QPixmap(iconSize, iconSize);
365 m_emptyIcon.fill(Qt::transparent);
367 ~KEditToolBarWidgetPrivate()
372 void slotToolBarSelected(
int index);
374 void slotInactiveSelectionChanged();
375 void slotActiveSelectionChanged();
377 void slotInsertButton();
378 void slotRemoveButton();
380 void slotDownButton();
382 void selectActiveItem(
const QString&);
384 void slotChangeIcon();
385 void slotChangeIconText();
387 void slotProcessExited();
389 void slotDropped(ToolBarListWidget* list,
int index, ToolBarItem* item,
bool sourceIsActiveList);
394 void initOldStyle(
const QString& file,
bool global,
const QString& defaultToolbar );
396 void loadToolBarCombo(
const QString& defaultToolbar );
397 void loadActions(
const QDomElement& elem);
401 return xml_file.isEmpty() ?
QString(m_componentData.componentName()) +
"ui.rc" :
411 QString xml_file = xmlFile(_xml_file);
414 if ( !QDir::isRelativePath(xml_file) )
425 QDomElement findElementForToolBarItem(
const ToolBarItem* item )
const
429 for(QDomNode n = m_currentToolBarElem.firstChild(); !n.isNull(); n = n.nextSibling())
431 QDomElement elem = n.toElement();
432 if ((elem.attribute(attrName) == item->internalName()) &&
433 (elem.tagName() == item->internalTag()))
437 return QDomElement();
440 void insertActive(ToolBarItem *item, ToolBarItem *before,
bool prepend =
false);
441 void removeActive(ToolBarItem *item);
442 void moveActive(ToolBarItem *item, ToolBarItem *before);
443 void updateLocal(QDomElement& elem);
448 XmlDataList::const_iterator xit = m_xmlFiles.begin();
449 for ( ; xit != m_xmlFiles.end(); ++xit ) {
464 KEditToolBarWidget* m_widget;
470 XmlData* m_currentXmlData;
471 QDomElement m_currentToolBarElem;
476 QDomDocument m_localDoc;
479 ToolBarListWidget *m_inactiveList;
480 ToolBarListWidget *m_activeList;
491 bool m_hasKDialog : 1;
492 bool m_loadedOnce : 1;
497 using namespace KDEPrivate;
500 class KEditToolBarPrivate {
503 m_accept(false), m_global(false),
504 m_collection(0), m_factory(0), m_widget(0) {}
510 void _k_acceptOK(
bool);
511 void _k_slotDefault();
521 KEditToolBarWidget *m_widget;
529 d(new KEditToolBarPrivate(this))
531 d->m_widget =
new KEditToolBarWidget( collection,
this);
533 d->m_collection = collection;
539 d(new KEditToolBarPrivate(this))
541 d->m_widget =
new KEditToolBarWidget(
this);
543 d->m_factory = factory;
546 void KEditToolBarPrivate::init()
551 q->setDefaultToolBar(
QString() );
553 q->setCaption(
i18n(
"Configure Toolbars"));
559 q->setMainWidget(m_widget);
561 q->connect(m_widget, SIGNAL(enableOk(
bool)), SLOT(_k_acceptOK(
bool)));
562 q->connect(m_widget, SIGNAL(enableOk(
bool)), SLOT(enableButtonApply(
bool)));
563 q->enableButtonApply(
false);
565 q->connect(q, SIGNAL(okClicked()), SLOT(_k_slotOk()));
566 q->connect(q, SIGNAL(applyClicked()), SLOT(_k_slotApply()));
567 q->connect(q, SIGNAL(defaultClicked()), SLOT(_k_slotDefault()));
569 q->setMinimumSize(q->sizeHint());
575 d->m_global = global;
576 d->m_widget->load( d->m_file, d->m_global, d->m_defaultToolBar );
582 s_defaultToolBarName->clear();
587 if ( toolBarName.isEmpty() ) {
588 d->m_defaultToolBar = *s_defaultToolBarName;
590 d->m_defaultToolBar = toolBarName;
594 void KEditToolBarPrivate::_k_acceptOK(
bool b)
596 q->enableButtonOk(b);
600 void KEditToolBarPrivate::_k_slotDefault()
605 KEditToolBarWidget * oldWidget = m_widget;
616 kDebug(240) <<
"Deleting local xml file" << file;
618 if ( QFile::exists( file ) )
620 kWarning() <<
"Could not delete" << file;
624 oldWidget->rebuildKXMLGUIClients();
626 m_widget =
new KEditToolBarWidget( q );
627 m_widget->load( m_factory, m_defaultToolBar );
631 int slash = m_file.lastIndexOf(
'/')+1;
633 m_file = m_file.mid(slash);
636 if ( QFile::exists( xml_file ) )
638 kWarning() <<
"Could not delete " << xml_file;
640 m_widget =
new KEditToolBarWidget( m_collection, q );
641 q->setResourceFile( m_file, m_global );
645 m_widget->setGeometry( oldWidget->geometry() );
646 q->setMainWidget(m_widget);
649 q->connect(m_widget, SIGNAL(enableOk(
bool)), SLOT(_k_acceptOK(
bool)));
650 q->connect(m_widget, SIGNAL(enableOk(
bool)), SLOT(enableButtonApply(
bool)));
652 q->enableButtonApply(
false);
654 emit q->newToolBarConfig();
655 emit q->newToolbarConfig();
658 void KEditToolBarPrivate::_k_slotOk()
665 if (!m_widget->save())
674 emit q->newToolBarConfig();
675 emit q->newToolbarConfig();
681 void KEditToolBarPrivate::_k_slotApply()
683 (void)m_widget->save();
684 q->enableButtonApply(
false);
685 emit q->newToolBarConfig();
686 emit q->newToolbarConfig();
691 *s_defaultToolBarName = QString::fromLatin1(toolbarName);
697 d(new KEditToolBarWidgetPrivate(this, componentData(), collection))
702 KEditToolBarWidget::KEditToolBarWidget(
QWidget *parent )
704 d(new KEditToolBarWidgetPrivate(this, componentData(),
KXMLGUIClient::actionCollection() ))
709 KEditToolBarWidget::~KEditToolBarWidget()
714 void KEditToolBarWidget::load(
const QString& file,
bool global,
const QString& defaultToolBar )
716 d->initOldStyle( file, global, defaultToolBar );
721 d->initFromFactory( factory, defaultToolBar );
724 void KEditToolBarWidgetPrivate::initOldStyle(
const QString& resourceFile,
726 const QString& defaultToolBar )
729 if ( m_loadedOnce ) {
738 m_widget->loadStandardsXmlFile();
739 const QString localXML = loadXMLFile( resourceFile );
740 m_widget->setXML(localXML, global ?
true :
false);
743 XmlData local(XmlData::Local, xmlFile(resourceFile), m_collection);
745 domDoc.setContent(localXML);
746 local.setDomDocument(domDoc);
747 m_xmlFiles.append(local);
750 XmlData merge(XmlData::Merged,
QString(), m_collection);
751 merge.setDomDocument(m_widget->domDocument());
752 m_xmlFiles.append(merge);
759 loadToolBarCombo( defaultToolBar );
760 m_widget->adjustSize();
761 m_widget->setMinimumSize( m_widget->sizeHint() );
764 void KEditToolBarWidgetPrivate::initFromFactory(
KXMLGUIFactory* factory,
768 if ( m_loadedOnce ) {
780 if (client->
xmlFile().isEmpty())
783 XmlData::XmlType type = XmlData::Part;
785 type = XmlData::Shell;
792 data.setDomDocument(domDoc);
793 m_xmlFiles.append(data);
803 loadToolBarCombo( defaultToolBar );
804 m_widget->adjustSize();
805 m_widget->setMinimumSize( m_widget->sizeHint() );
807 m_widget->actionCollection()->addAssociatedWidget( m_widget );
808 foreach (
QAction* action, m_widget->actionCollection()->actions())
809 action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
815 XmlDataList::Iterator it = d->m_xmlFiles.begin();
816 for ( ; it != d->m_xmlFiles.end(); ++it)
819 if ( !((*it).m_isModified) )
823 if ( (*it).type() == XmlData::Merged )
827 QDomNodeList menuNodes = (*it).domDocument().elementsByTagName(
"Menu" );
828 for (uint i = 0; i < menuNodes.length(); ++i)
830 QDomNode menuNode = menuNodes.item(i);
831 QDomElement menuElement = menuNode.toElement();
832 if (menuElement.isNull())
continue;
833 menuElement.setAttribute(
"noMerge",
"1" );
836 kDebug() << (*it).domDocument().toString();
838 kDebug(240) <<
"Saving " << (*it).xmlFile();
846 rebuildKXMLGUIClients();
851 void KEditToolBarWidget::rebuildKXMLGUIClients()
860 if (!clients.count())
863 QListIterator<KXMLGUIClient*> clientIterator = clients;
864 clientIterator.toBack();
865 while (clientIterator.hasPrevious()) {
868 d->m_factory->removeClient(client);
879 if ( !file.isEmpty() )
885 if ( client == firstClient )
889 client->
setXMLFile( file, client == firstClient );
899 d->m_factory->addClient(client);
903 void KEditToolBarWidgetPrivate::setupLayout()
906 m_comboLabel =
new QLabel(
i18n(
"&Toolbar:"), m_widget);
907 m_toolbarCombo =
new KComboBox(m_widget);
908 m_comboLabel->setBuddy(m_toolbarCombo);
910 QObject::connect(m_toolbarCombo, SIGNAL(activated(
int)),
911 m_widget, SLOT(slotToolBarSelected(
int)));
922 m_inactiveList =
new ToolBarListWidget(m_widget);
923 m_inactiveList->setDragEnabled(
true);
924 m_inactiveList->setActiveList(
false);
925 m_inactiveList->setMinimumSize(180, 250);
926 m_inactiveList->setDropIndicatorShown(
false);
927 inactive_label->setBuddy(m_inactiveList);
928 QObject::connect(m_inactiveList, SIGNAL(itemSelectionChanged()),
929 m_widget, SLOT(slotInactiveSelectionChanged()));
930 QObject::connect(m_inactiveList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
931 m_widget, SLOT(slotInsertButton()));
932 QObject::connect(m_inactiveList, SIGNAL(dropped(ToolBarListWidget*,
int,ToolBarItem*,
bool)),
933 m_widget, SLOT(slotDropped(ToolBarListWidget*,
int,ToolBarItem*,
bool)));
940 m_activeList =
new ToolBarListWidget(m_widget);
941 m_activeList->setDragEnabled(
true);
942 m_activeList->setActiveList(
true);
944 m_activeList->setMinimumSize(m_inactiveList->minimumWidth(), 100);
945 active_label->setBuddy(m_activeList);
947 QObject::connect(m_activeList, SIGNAL(itemSelectionChanged()),
948 m_widget, SLOT(slotActiveSelectionChanged()));
949 QObject::connect(m_activeList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
950 m_widget, SLOT(slotRemoveButton()));
951 QObject::connect(m_activeList, SIGNAL(dropped(ToolBarListWidget*,
int,ToolBarItem*,
bool)),
952 m_widget, SLOT(slotDropped(ToolBarListWidget*,
int,ToolBarItem*,
bool)));
959 m_changeIcon->setIcon(
KIcon(
"preferences-desktop-icons"));
961 m_hasKDialog = !kdialogExe.isEmpty();
962 m_changeIcon->setEnabled(m_hasKDialog && m_activeList->currentItem());
964 QObject::connect( m_changeIcon, SIGNAL(clicked()),
965 m_widget, SLOT(slotChangeIcon()) );
968 m_changeIconText =
new KPushButton(
i18n(
"Change Te&xt..." ), m_widget);
969 m_changeIconText->setIcon(
KIcon(
"edit-rename"));
970 m_changeIconText->setEnabled(m_activeList->currentItem() != 0);
972 QObject::connect( m_changeIconText, SIGNAL(clicked()),
973 m_widget, SLOT(slotChangeIconText()) );
978 m_upAction->setIcon(
KIcon(
"go-up") );
979 m_upAction->setEnabled(
false);
980 m_upAction->setAutoRepeat(
true);
981 QObject::connect(m_upAction, SIGNAL(clicked()), m_widget, SLOT(slotUpButton()));
984 m_insertAction->setIcon(
KIcon(QApplication::isRightToLeft() ?
"go-previous" :
"go-next") );
985 m_insertAction->setEnabled(
false);
986 QObject::connect(m_insertAction, SIGNAL(clicked()), m_widget, SLOT(slotInsertButton()));
989 m_removeAction->setIcon(
KIcon(QApplication::isRightToLeft() ?
"go-next" :
"go-previous") );
990 m_removeAction->setEnabled(
false);
991 QObject::connect(m_removeAction, SIGNAL(clicked()), m_widget, SLOT(slotRemoveButton()));
994 m_downAction->setIcon(
KIcon(
"go-down") );
995 m_downAction->setEnabled(
false);
996 m_downAction->setAutoRepeat(
true);
997 QObject::connect(m_downAction, SIGNAL(clicked()), m_widget, SLOT(slotDownButton()));
999 m_helpArea =
new QLabel(m_widget);
1000 m_helpArea->setWordWrap(
true);
1003 QVBoxLayout *top_layout =
new QVBoxLayout(m_widget);
1004 top_layout->setMargin(0);
1006 QVBoxLayout *name_layout =
new QVBoxLayout();
1007 QHBoxLayout *list_layout =
new QHBoxLayout();
1009 QVBoxLayout *inactive_layout =
new QVBoxLayout();
1010 QVBoxLayout *active_layout =
new QVBoxLayout();
1011 QHBoxLayout *changeIcon_layout =
new QHBoxLayout();
1013 QGridLayout *button_layout =
new QGridLayout();
1015 name_layout->addWidget(m_comboLabel);
1016 name_layout->addWidget(m_toolbarCombo);
1020 button_layout->setSpacing( 0 );
1021 button_layout->setRowStretch( 0, 10 );
1022 button_layout->addWidget(m_upAction, 1, 1);
1023 button_layout->addWidget(m_removeAction, 2, 0);
1024 button_layout->addWidget(m_insertAction, 2, 2);
1025 button_layout->addWidget(m_downAction, 3, 1);
1026 button_layout->setRowStretch( 4, 10 );
1028 inactive_layout->addWidget(inactive_label);
1029 inactive_layout->addWidget(inactiveListSearchLine);
1030 inactive_layout->addWidget(m_inactiveList, 1);
1032 active_layout->addWidget(active_label);
1033 active_layout->addWidget(activeListSearchLine);
1034 active_layout->addWidget(m_activeList, 1);
1035 active_layout->addLayout(changeIcon_layout);
1037 changeIcon_layout->addWidget(m_changeIcon);
1038 changeIcon_layout->addStretch( 1 );
1039 changeIcon_layout->addWidget(m_changeIconText);
1041 list_layout->addLayout(inactive_layout);
1042 list_layout->addLayout(button_layout);
1043 list_layout->addLayout(active_layout);
1045 top_layout->addLayout(name_layout);
1046 top_layout->addWidget(m_comboSeparator);
1047 top_layout->addLayout(list_layout,10);
1048 top_layout->addWidget(m_helpArea);
1049 top_layout->addWidget(
new KSeparator(m_widget));
1052 void KEditToolBarWidgetPrivate::loadToolBarCombo(
const QString& defaultToolBar )
1054 const QLatin1String attrName(
"name" );
1056 m_toolbarCombo->clear();
1058 int defaultToolBarId = -1;
1061 XmlDataList::const_iterator xit = m_xmlFiles.constBegin();
1062 for ( ; xit != m_xmlFiles.constEnd(); ++xit)
1067 if ( (*xit).type() == XmlData::Merged )
1071 ToolBarList::const_iterator it = (*xit).barList().begin();
1072 for ( ; it != (*xit).barList().constEnd(); ++it)
1074 const QString text = (*xit).toolBarText( *it );
1075 m_toolbarCombo->addItem( text );
1076 const QString name = (*it).attribute(attrName);
1077 if (defaultToolBarId == -1 && name == defaultToolBar)
1078 defaultToolBarId = count;
1082 const bool showCombo = (count > 1);
1083 m_comboLabel->setVisible(showCombo);
1084 m_comboSeparator->setVisible(showCombo);
1085 m_toolbarCombo->setVisible(showCombo);
1086 if (defaultToolBarId == -1)
1087 defaultToolBarId = 0;
1089 m_toolbarCombo->setCurrentIndex(defaultToolBarId);
1090 slotToolBarSelected(m_toolbarCombo->currentIndex());
1093 void KEditToolBarWidgetPrivate::loadActions(
const QDomElement& elem)
1095 const QLatin1String tagSeparator(
"Separator" );
1096 const QLatin1String tagMerge(
"Merge" );
1097 const QLatin1String tagActionList(
"ActionList" );
1098 const QLatin1String tagAction(
"Action" );
1099 const QLatin1String attrName(
"name" );
1102 QString sep_name(
"separator_%1");
1105 m_inactiveList->clear();
1106 m_activeList->clear();
1107 m_insertAction->setEnabled(
false);
1108 m_removeAction->setEnabled(
false);
1109 m_upAction->setEnabled(
false);
1110 m_downAction->setEnabled(
false);
1122 QDomNode n = elem.firstChild();
1123 for( ; !n.isNull(); n = n.nextSibling() )
1125 QDomElement it = n.toElement();
1126 if (it.isNull())
continue;
1127 if (it.tagName() == tagSeparator)
1129 ToolBarItem *act =
new ToolBarItem(m_activeList, tagSeparator, sep_name.arg(sep_num++),
QString());
1130 act->setSeparator(
true);
1132 it.setAttribute( attrName, act->internalName() );
1136 if (it.tagName() == tagMerge)
1139 QString name = it.attribute( attrName );
1140 ToolBarItem *act =
new ToolBarItem(m_activeList, tagMerge, name,
i18n(
"This element will be replaced with all the elements of an embedded component."));
1141 if ( name.isEmpty() )
1142 act->setText(
i18n(
"<Merge>"));
1144 act->setText(
i18n(
"<Merge %1>", name));
1148 if (it.tagName() == tagActionList)
1150 ToolBarItem *act =
new ToolBarItem(m_activeList, tagActionList, it.attribute(attrName),
i18n(
"This is a dynamic list of actions. You can move it, but if you remove it you will not be able to re-add it.") );
1151 act->setText(
i18n(
"ActionList: %1", it.attribute(attrName)));
1161 if (it.attribute( attrName ) == action->objectName())
1164 ToolBarItem *act =
new ToolBarItem(m_activeList, it.tagName(), action->objectName(), action->toolTip());
1166 act->setIcon(!action->icon().isNull() ? action->icon() : m_emptyIcon);
1167 act->setTextAlongsideIconHidden(action->priority() < QAction::NormalPriority);
1169 active_list.insert(action->objectName());
1179 if (active_list.contains(action->objectName()))
1182 ToolBarItem *act =
new ToolBarItem(m_inactiveList, tagAction, action->objectName(), action->toolTip());
1184 act->setIcon(!action->icon().isNull() ? action->icon() : m_emptyIcon);
1187 m_inactiveList->sortItems(Qt::AscendingOrder);
1190 ToolBarItem *act =
new ToolBarItem(0L, tagSeparator, sep_name.arg(sep_num++),
QString());
1191 act->setSeparator(
true);
1193 m_inactiveList->insertItem(0, act);
1198 return d->m_collection;
1201 void KEditToolBarWidgetPrivate::slotToolBarSelected(
int index)
1203 const QLatin1String attrName(
"name" );
1207 int toolbarNumber = 0;
1208 XmlDataList::iterator xit = m_xmlFiles.begin();
1209 for ( ; xit != m_xmlFiles.end(); ++xit) {
1213 if ( (*xit).type() == XmlData::Merged )
1217 ToolBarList::Iterator it = (*xit).barList().begin();
1218 for ( ; it != (*xit).barList().end(); ++it) {
1221 if (toolbarNumber == index) {
1224 m_currentXmlData = & (*xit);
1225 m_currentToolBarElem = *it;
1227 kDebug() <<
"found toolbar" << m_currentXmlData->toolBarText(*it) <<
"m_currentXmlData set to";
1228 m_currentXmlData->dump();
1231 Q_ASSERT( m_currentXmlData->type() != XmlData::Merged );
1234 loadActions(m_currentToolBarElem);
1236 if ((*xit).type() == XmlData::Part || (*xit).type() == XmlData::Shell)
1237 m_widget->setDOMDocument( (*xit).domDocument() );
1246 void KEditToolBarWidgetPrivate::slotInactiveSelectionChanged()
1248 if (m_inactiveList->selectedItems().count())
1250 m_insertAction->setEnabled(
true);
1251 QString statusText =
static_cast<ToolBarItem*
>(m_inactiveList->selectedItems().first())->statusText();
1252 m_helpArea->setText(
i18nc(
"@label Action tooltip in toolbar editor, below the action list",
"%1", statusText) );
1256 m_insertAction->setEnabled(
false);
1257 m_helpArea->setText(
QString() );
1261 void KEditToolBarWidgetPrivate::slotActiveSelectionChanged()
1263 ToolBarItem* toolitem = 0;
1264 if (!m_activeList->selectedItems().isEmpty())
1265 toolitem = static_cast<ToolBarItem *>(m_activeList->selectedItems().first());
1267 m_removeAction->setEnabled( toolitem );
1269 m_changeIcon->setEnabled( toolitem &&
1271 toolitem->internalTag() ==
"Action" );
1273 m_changeIconText->setEnabled( toolitem &&
1274 toolitem->internalTag() ==
"Action" );
1278 m_upAction->setEnabled(toolitem->index() != 0);
1279 m_downAction->setEnabled(toolitem->index() != toolitem->listWidget()->count() - 1);
1281 QString statusText = toolitem->statusText();
1282 m_helpArea->setText(
i18nc(
"@label Action tooltip in toolbar editor, below the action list",
"%1", statusText) );
1286 m_upAction->setEnabled(
false);
1287 m_downAction->setEnabled(
false);
1288 m_helpArea->setText(
QString() );
1292 void KEditToolBarWidgetPrivate::slotInsertButton()
1294 QString internalName =
static_cast<ToolBarItem *
>(m_inactiveList->currentItem())->internalName();
1296 insertActive(m_inactiveList->currentItem(), m_activeList->currentItem(),
false);
1298 emit m_widget->enableOk(
true);
1300 slotToolBarSelected( m_toolbarCombo->currentIndex() );
1302 selectActiveItem( internalName );
1305 void KEditToolBarWidgetPrivate::selectActiveItem(
const QString& internalName)
1307 int activeItemCount = m_activeList->count();
1308 for(
int i = 0; i < activeItemCount; i++)
1310 ToolBarItem * item =
static_cast<ToolBarItem *
>(m_activeList->item(i));
1311 if (item->internalName()==internalName)
1313 m_activeList->setCurrentItem(item);
1319 void KEditToolBarWidgetPrivate::slotRemoveButton()
1321 removeActive( m_activeList->currentItem() );
1323 slotToolBarSelected( m_toolbarCombo->currentIndex() );
1326 void KEditToolBarWidgetPrivate::insertActive(ToolBarItem *item, ToolBarItem *before,
bool prepend)
1336 QDomElement new_item;
1338 if (item->isSeparator())
1339 new_item = m_widget->domDocument().createElement(tagSeparator);
1341 new_item = m_widget->domDocument().createElement(tagAction);
1343 new_item.setAttribute(attrName, item->internalName());
1345 Q_ASSERT(!m_currentToolBarElem.isNull());
1351 QDomElement elem = findElementForToolBarItem( before );
1352 Q_ASSERT( !elem.isNull() );
1353 m_currentToolBarElem.insertAfter(new_item, elem);
1359 m_currentToolBarElem.insertBefore(new_item, m_currentToolBarElem.firstChild());
1361 m_currentToolBarElem.appendChild(new_item);
1365 m_currentToolBarElem.setAttribute( attrNoMerge,
"1");
1368 updateLocal(m_currentToolBarElem);
1371 void KEditToolBarWidgetPrivate::removeActive(ToolBarItem *item)
1379 emit m_widget->enableOk(
true);
1382 QDomElement elem = findElementForToolBarItem( item );
1383 if ( !elem.isNull() )
1386 m_currentToolBarElem.removeChild(elem);
1389 m_currentToolBarElem.setAttribute( attrNoMerge,
"1");
1392 updateLocal(m_currentToolBarElem);
1396 void KEditToolBarWidgetPrivate::slotUpButton()
1398 ToolBarItem *item = m_activeList->currentItem();
1405 int row = item->listWidget()->row(item) - 1;
1413 emit m_widget->enableOk(
true);
1415 moveActive( item, static_cast<ToolBarItem*>(item->listWidget()->item(row - 1)) );
1418 void KEditToolBarWidgetPrivate::moveActive( ToolBarItem* item, ToolBarItem* before )
1420 QDomElement e = findElementForToolBarItem( item );
1426 m_activeList->takeItem(m_activeList->row(item));
1429 m_activeList->insertItem(m_activeList->row(before) + 1, item);
1432 m_activeList->setCurrentItem(item);
1436 m_currentToolBarElem.insertBefore(e, m_currentToolBarElem.firstChild() );
1438 m_currentToolBarElem.insertAfter(e, findElementForToolBarItem( (ToolBarItem*)before ));
1442 m_currentToolBarElem.setAttribute( attrNoMerge,
"1");
1445 updateLocal(m_currentToolBarElem);
1448 void KEditToolBarWidgetPrivate::slotDownButton()
1450 ToolBarItem *item = m_activeList->currentItem();
1458 int newRow = item->listWidget()->row(item) + 1;
1459 if (newRow >= item->listWidget()->count()) {
1465 emit m_widget->enableOk(
true);
1467 moveActive( item, static_cast<ToolBarItem*>(item->listWidget()->item(newRow)) );
1470 void KEditToolBarWidgetPrivate::updateLocal(QDomElement& elem)
1474 XmlDataList::Iterator xit = m_xmlFiles.begin();
1475 for ( ; xit != m_xmlFiles.end(); ++xit)
1477 if ( (*xit).type() == XmlData::Merged )
1480 if ( (*xit).type() == XmlData::Shell ||
1481 (*xit).type() == XmlData::Part )
1483 if ( m_currentXmlData->xmlFile() == (*xit).xmlFile() )
1485 (*xit).m_isModified =
true;
1492 (*xit).m_isModified =
true;
1494 ToolBarList::Iterator it = (*xit).barList().begin();
1495 for ( ; it != (*xit).barList().end(); ++it)
1498 QString tag( (*it).tagName() );
1499 if ( (tag != elem.tagName()) || (name != elem.attribute(attrName)) )
1502 QDomElement toolbar = (*xit).domDocument().documentElement().toElement();
1503 toolbar.replaceChild(elem, (*it));
1508 QDomElement toolbar = (*xit).domDocument().documentElement().toElement();
1509 Q_ASSERT(!toolbar.isNull());
1510 toolbar.appendChild(elem);
1514 void KEditToolBarWidgetPrivate::slotChangeIcon()
1522 if ( m_kdialogProcess && m_kdialogProcess->state() == QProcess::Running )
1525 m_currentXmlData->dump();
1526 Q_ASSERT( m_currentXmlData->type() != XmlData::Merged );
1530 (*m_kdialogProcess) << kdialogExe;
1531 (*m_kdialogProcess) <<
"--caption";
1532 (*m_kdialogProcess) <<
i18n(
"Change Icon" );
1533 (*m_kdialogProcess) <<
"--embed";
1534 (*m_kdialogProcess) << QString::number( (quintptr)m_widget->window()->winId() );
1535 (*m_kdialogProcess) <<
"--geticon";
1536 (*m_kdialogProcess) <<
"Toolbar";
1537 (*m_kdialogProcess) <<
"Actions";
1539 m_kdialogProcess->setNextOpenMode( QIODevice::ReadOnly | QIODevice::Text );
1540 m_kdialogProcess->start();
1541 if ( !m_kdialogProcess->waitForStarted() ) {
1542 kError(240) <<
"Can't run " << kdialogExe << endl;
1543 delete m_kdialogProcess;
1544 m_kdialogProcess = 0;
1548 m_activeList->setEnabled(
false );
1549 m_toolbarCombo->setEnabled(
false );
1551 QObject::connect( m_kdialogProcess, SIGNAL(finished(
int,QProcess::ExitStatus)),
1552 m_widget, SLOT(slotProcessExited()) );
1555 void KEditToolBarWidgetPrivate::slotChangeIconText()
1557 m_currentXmlData->dump();
1558 ToolBarItem *item = m_activeList->currentItem();
1561 QString iconText = item->text();
1562 bool hidden = item->isTextAlongsideIconHidden();
1564 IconTextEditDialog dialog(m_widget);
1565 dialog.setIconText(iconText);
1566 dialog.setTextAlongsideIconHidden(hidden);
1568 bool ok = dialog.exec() == KDialog::Accepted;
1569 iconText = dialog.iconText();
1570 hidden = dialog.textAlongsideIconHidden();
1572 bool hiddenChanged = hidden != item->isTextAlongsideIconHidden();
1573 bool iconTextChanged = iconText != item->text();
1575 if (!ok || (!hiddenChanged && !iconTextChanged))
1578 item->setText(iconText);
1579 item->setTextAlongsideIconHidden(hidden);
1581 Q_ASSERT( m_currentXmlData->type() != XmlData::Merged );
1583 m_currentXmlData->m_isModified =
true;
1589 Q_ASSERT( !act_elem.isNull() );
1590 if (iconTextChanged)
1591 act_elem.setAttribute(
"iconText", iconText );
1593 act_elem.setAttribute(
"priority", hidden ? QAction::LowPriority : QAction::NormalPriority );
1596 emit m_widget->enableOk(
true);
1600 void KEditToolBarWidgetPrivate::slotProcessExited()
1602 m_activeList->setEnabled(
true );
1603 m_toolbarCombo->setEnabled(
true );
1607 if (!m_kdialogProcess) {
1608 kError(240) <<
"Something is wrong here! m_kdialogProcess is zero!" << endl;
1612 icon = QString::fromLocal8Bit( m_kdialogProcess->readLine() );
1613 icon = icon.left( icon.indexOf(
'\n' ) );
1614 kDebug(240) <<
"icon=" << icon;
1615 if ( m_kdialogProcess->exitStatus() != QProcess::NormalExit ||
1617 delete m_kdialogProcess;
1618 m_kdialogProcess = 0;
1622 ToolBarItem *item = m_activeList->currentItem();
1625 item->setIcon(
KIcon(icon));
1627 Q_ASSERT( m_currentXmlData->type() != XmlData::Merged );
1629 m_currentXmlData->m_isModified =
true;
1635 Q_ASSERT( !act_elem.isNull() );
1636 act_elem.setAttribute(
"icon", icon );
1639 emit m_widget->enableOk(
true);
1642 delete m_kdialogProcess;
1643 m_kdialogProcess = 0;
1646 void KEditToolBarWidgetPrivate::slotDropped(ToolBarListWidget* list,
int index, ToolBarItem* item,
bool sourceIsActiveList)
1650 if (list == m_activeList) {
1651 ToolBarItem* after = index > 0 ?
static_cast<ToolBarItem *
>(list->item(index-1)) : 0;
1653 if (sourceIsActiveList) {
1655 moveActive(item, after);
1658 insertActive(item, after,
true);
1660 }
else if (list == m_inactiveList) {
1668 emit m_widget->enableOk(
true);
1670 slotToolBarSelected( m_toolbarCombo->currentIndex() );
1676 if (!event->spontaneous()) {
1678 if ( d->m_factory ) {
1680 d->m_widget->load( d->m_factory, d->m_defaultToolBar );
1683 d->m_widget->load( d->m_file, d->m_global, d->m_defaultToolBar );
1688 KDialog::showEvent(event);
1699 #include "kedittoolbar.moc"
1700 #include "kedittoolbar_p.moc"
QString i18n(const char *text)
A container for a set of QAction objects.
virtual KActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected) ...
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
#define K_GLOBAL_STATIC(TYPE, NAME)
void loadStandardsXmlFile()
Load the ui_standards.rc file.
const char * name(StandardAction id)
This will return the internal name of a given standard action.
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
virtual void setXMLFile(const QString &file, bool merge=false, bool setXMLDoc=true)
Sets the name of the rc file containing the XML for the part.
QList< XmlData > XmlDataList
A dialog base class with standard buttons and predefined layouts.
virtual QString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
virtual QString localXMLFile() const
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QString i18nc(const char *ctxt, const char *text)
Standard horizontal or vertical separator.
KGuiItem remove()
Returns the 'Remove' gui item.
An abstract class for GUI data such as ToolTip and Icon.
static QString readConfigFile(const QString &filename, const KComponentData &componentData=KComponentData())
QList< QAction * > actions() const
Returns the list of KActions which belong to this action collection.
A wrapper around QIcon that provides KDE icon features.
static QDataStream & operator>>(QDataStream &s, ToolBarItem &item)
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted) ...
KXMLGUIFactory, together with KXMLGUIClient objects, can be used to create a GUI of container widgets...
KGuiItem ok()
Returns the 'Ok' gui item.
QString removeAcceleratorMarker(const QString &label) const
An enhanced QLineEdit widget for inputting text.
static QString locateLocal(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
KLocalizedString ki18nc(const char *ctxt, const char *msg)
virtual void hideEvent(QHideEvent *)
Emits the hidden signal.
static QString findExe(const QString &appname, const QString &pathstr=QString(), SearchOptions options=NoSearchOptions)
const KComponentData & mainComponent()
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KLocalizedString subs(int a, int fieldWidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const
virtual QDomDocument domDocument() const
void setFlags(CrashFlags flags)
Set options to determine how the default crash handler should behave.
void setClickMessage(const QString &msg)
This makes the line edit display a grayed-out hinting text as long as the user didn't enter any text...
const QString & staticQString(const char *str)
QList< KXMLGUIClient * > clients() const
Returns a list of all clients currently added to this factory.
static QDataStream & operator<<(QDataStream &s, const ToolBarItem &item)
KAction * save(const QObject *recvr, const char *slot, QObject *parent)
Save the current document.
static bool saveConfigFile(const QDomDocument &doc, const QString &filename, const KComponentData &componentData=KComponentData())
static ToolBarList findToolBars(const QDomElement &start)
Return a list of toolbar elements given a toplevel element.
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
Display a "warning" dialog.
static QDomElement actionPropertiesElement(QDomDocument &doc)
static QDomElement findActionByName(QDomElement &elem, const QString &sName, bool create)
void setXMLGUIBuildDocument(const QDomDocument &doc)