diff options
Diffstat (limited to 'src/modules/popupeditor/PopupEditorWindow.cpp')
| -rw-r--r-- | src/modules/popupeditor/PopupEditorWindow.cpp | 826 |
1 files changed, 447 insertions, 379 deletions
diff --git a/src/modules/popupeditor/PopupEditorWindow.cpp b/src/modules/popupeditor/PopupEditorWindow.cpp index feedfddac..6faee9739 100644 --- a/src/modules/popupeditor/PopupEditorWindow.cpp +++ b/src/modules/popupeditor/PopupEditorWindow.cpp @@ -52,21 +52,18 @@ #include <QPushButton> #include <QAbstractItemView> - extern PopupEditorWindow * g_pPopupEditorWindow; - - //KviPopupEntryItem -PopupTreeWidgetItem::PopupTreeWidgetItem(QTreeWidget * pTreeWidget,PopupTreeWidgetItem * after,Type t) -: QTreeWidgetItem(pTreeWidget, after) +PopupTreeWidgetItem::PopupTreeWidgetItem(QTreeWidget * pTreeWidget, PopupTreeWidgetItem * after, Type t) + : QTreeWidgetItem(pTreeWidget, after) { m_type = t; init(); } -PopupTreeWidgetItem::PopupTreeWidgetItem(PopupTreeWidgetItem * parent,PopupTreeWidgetItem * after,Type t) -: QTreeWidgetItem(parent, after) +PopupTreeWidgetItem::PopupTreeWidgetItem(PopupTreeWidgetItem * parent, PopupTreeWidgetItem * after, Type t) + : QTreeWidgetItem(parent, after) { m_type = t; init(); @@ -77,31 +74,31 @@ void PopupTreeWidgetItem::init() switch(m_type) { case Item: - setText(1,__tr2qs_ctx("Item","editor")); - break; + setText(1, __tr2qs_ctx("Item", "editor")); + break; case Menu: - setText(1,__tr2qs_ctx("Submenu","editor")); - break; + setText(1, __tr2qs_ctx("Submenu", "editor")); + break; case ExtMenu: - setText(1,__tr2qs_ctx("External Menu","editor")); - break; + setText(1, __tr2qs_ctx("External Menu", "editor")); + break; case Separator: - setText(0,"-----------------------"); - setText(1,__tr2qs_ctx("Separator","editor")); - break; + setText(0, "-----------------------"); + setText(1, __tr2qs_ctx("Separator", "editor")); + break; case Label: - setText(1,__tr2qs_ctx("Label","editor")); - break; + setText(1, __tr2qs_ctx("Label", "editor")); + break; case Epilogue: - setText(0,__tr2qs_ctx("### Epilogue ###","editor")); - setText(1,__tr2qs_ctx("Epilogue","editor")); - break; + setText(0, __tr2qs_ctx("### Epilogue ###", "editor")); + setText(1, __tr2qs_ctx("Epilogue", "editor")); + break; case Prologue: - setText(0,__tr2qs_ctx("### Prologue ###","editor")); - setText(1,__tr2qs_ctx("Prologue","editor")); - break; + setText(0, __tr2qs_ctx("### Prologue ###", "editor")); + setText(1, __tr2qs_ctx("Prologue", "editor")); + break; default: - break; + break; } } @@ -114,10 +111,10 @@ void PopupTreeWidgetItem::setItemText(const QString & szText) case Label: case ExtMenu: m_szText = szText; - setText(0,szText); - break; + setText(0, szText); + break; default: - break; + break; } } @@ -131,9 +128,9 @@ void PopupTreeWidgetItem::setCondition(const QString & szCondition) case ExtMenu: case Separator: m_szCondition = szCondition; - break; + break; default: - break; + break; } } @@ -146,9 +143,9 @@ void PopupTreeWidgetItem::setCode(const QString & szCode) case Prologue: case ExtMenu: m_szCode = szCode; - break; + break; default: - break; + break; } } @@ -169,19 +166,18 @@ void PopupTreeWidgetItem::setIcon(const QString & szIcon) { QPixmap * pix = g_pIconManager->getImage(szIcon); if(pix) - QTreeWidgetItem::setIcon(0,QIcon(*pix)); + QTreeWidgetItem::setIcon(0, QIcon(*pix)); else - QTreeWidgetItem::setIcon(0,QIcon()); + QTreeWidgetItem::setIcon(0, QIcon()); } - break; + break; default: - break; + break; } } - SinglePopupEditor::SinglePopupEditor(QWidget * par) -: QWidget(par) + : QWidget(par) { m_pLastSelectedItem = nullptr; m_pContextPopup = new QMenu(this); @@ -193,21 +189,21 @@ SinglePopupEditor::SinglePopupEditor(QWidget * par) g->setSpacing(2); m_pNameEditor = new QLineEdit(this); - m_pNameEditor->setToolTip(__tr2qs_ctx("Popup name","editor")); + m_pNameEditor->setToolTip(__tr2qs_ctx("Popup name", "editor")); - g->addWidget(m_pNameEditor,0,0,1,2); + g->addWidget(m_pNameEditor, 0, 0, 1, 2); - m_pMenuButton = new QPushButton(__tr2qs_ctx("Test","editor"),this); - g->addWidget(m_pMenuButton,0,2); - connect(m_pMenuButton,SIGNAL(clicked()),this,SLOT(testPopup())); - QSplitter * spl = new QSplitter(Qt::Vertical,this); + m_pMenuButton = new QPushButton(__tr2qs_ctx("Test", "editor"), this); + g->addWidget(m_pMenuButton, 0, 2); + connect(m_pMenuButton, SIGNAL(clicked()), this, SLOT(testPopup())); + QSplitter * spl = new QSplitter(Qt::Vertical, this); spl->setObjectName("popupeditor_vertical_splitter"); spl->setChildrenCollapsible(false); m_pTreeWidget = new QTreeWidget(spl); m_pTreeWidget->setColumnCount(2); QStringList labels; - labels << __tr2qs_ctx("Item","editor") << __tr2qs_ctx("Type","editor"); + labels << __tr2qs_ctx("Item", "editor") << __tr2qs_ctx("Type", "editor"); m_pTreeWidget->setHeaderLabels(labels); m_pTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); m_pTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -217,60 +213,59 @@ SinglePopupEditor::SinglePopupEditor(QWidget * par) m_pTreeWidget->setSortingEnabled(false); m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(m_pTreeWidget,SIGNAL(itemSelectionChanged()),this,SLOT(selectionChanged())); - connect(m_pTreeWidget,SIGNAL(customContextMenuRequested(const QPoint &)), - this,SLOT(customContextMenuRequested(const QPoint &))); + connect(m_pTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged())); + connect(m_pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(customContextMenuRequested(const QPoint &))); m_pEditor = KviScriptEditor::createInstance(spl); - g->addWidget(spl,1,0,1,3); + g->addWidget(spl, 1, 0, 1, 3); - QLabel * l = new QLabel(__tr2qs_ctx("Text:","editor"),this); - g->addWidget(l,2,0); + QLabel * l = new QLabel(__tr2qs_ctx("Text:", "editor"), this); + g->addWidget(l, 2, 0); m_pTextEditor = new QLineEdit(this); m_pTextEditor->setToolTip( - __tr2qs_ctx("<b>Visible text</b><br>May contain identifiers that will be evaluated at popup call time.<br>For labels, this text can contain also limited HTML tags.","editor")); - g->addWidget(m_pTextEditor,2,1,1,2); + __tr2qs_ctx("<b>Visible text</b><br>May contain identifiers that will be evaluated at popup call time.<br>For labels, this text can contain also limited HTML tags.", "editor")); + g->addWidget(m_pTextEditor, 2, 1, 1, 2); - l = new QLabel(__tr2qs_ctx("Condition:","editor"),this); + l = new QLabel(__tr2qs_ctx("Condition:", "editor"), this); l->setMargin(2); - g->addWidget(l,3,0); + g->addWidget(l, 3, 0); m_pConditionEditor = new QLineEdit(this); m_pConditionEditor->setToolTip( - __tr2qs_ctx("<b>Boolean condition</b><br>Will be evaluated at popup call time in order to decide if this entry has to be shown.<br>An empty condition evaluates to true.","editor")); - g->addWidget(m_pConditionEditor,3,1,1,2); + __tr2qs_ctx("<b>Boolean condition</b><br>Will be evaluated at popup call time in order to decide if this entry has to be shown.<br>An empty condition evaluates to true.", "editor")); + g->addWidget(m_pConditionEditor, 3, 1, 1, 2); - l = new QLabel(__tr2qs_ctx("Icon:","editor"),this); + l = new QLabel(__tr2qs_ctx("Icon:", "editor"), this); l->setMargin(2); - g->addWidget(l,4,0); + g->addWidget(l, 4, 0); m_pIconEditor = new QLineEdit(this); m_pIconEditor->setToolTip( - __tr2qs_ctx("<b>Icon identifier</b><br>May be an internal icon ID, an absolute path or a relative path.<br>Portable scripts should never use absolute paths.","editor")); - g->addWidget(m_pIconEditor,4,1,1,2); + __tr2qs_ctx("<b>Icon identifier</b><br>May be an internal icon ID, an absolute path or a relative path.<br>Portable scripts should never use absolute paths.", "editor")); + g->addWidget(m_pIconEditor, 4, 1, 1, 2); - l = new QLabel(__tr2qs_ctx("External menu:","editor"),this); + l = new QLabel(__tr2qs_ctx("External menu:", "editor"), this); l->setMargin(2); - g->addWidget(l,5,0); + g->addWidget(l, 5, 0); m_pExtNameEditor = new QLineEdit(this); m_pExtNameEditor->setToolTip( - __tr2qs_ctx("<b>External menu name</b><br>This allows one to nest externally defined popup menus. The popup menu with the specified name will be looked up at menu setup time.","editor")); - g->addWidget(m_pExtNameEditor,5,1,1,2); + __tr2qs_ctx("<b>External menu name</b><br>This allows one to nest externally defined popup menus. The popup menu with the specified name will be looked up at menu setup time.", "editor")); + g->addWidget(m_pExtNameEditor, 5, 1, 1, 2); - l = new QLabel(__tr2qs_ctx("Item ID:","editor"),this); + l = new QLabel(__tr2qs_ctx("Item ID:", "editor"), this); l->setMargin(2); - g->addWidget(l,6,0); - + g->addWidget(l, 6, 0); m_pIdEditor = new QLineEdit(this); m_pIdEditor->setToolTip( - __tr2qs_ctx("<b>Item ID</b><br>This will allow you to use delpopupitem later.","editor")); - g->addWidget(m_pIdEditor,6,1,1,2); - g->setColumnStretch(1,1); - g->setRowStretch(1,1); + __tr2qs_ctx("<b>Item ID</b><br>This will allow you to use delpopupitem later.", "editor")); + g->addWidget(m_pIdEditor, 6, 1, 1, 2); + g->setColumnStretch(1, 1); + g->setRowStretch(1, 1); } SinglePopupEditor::~SinglePopupEditor() @@ -283,59 +278,81 @@ SinglePopupEditor::~SinglePopupEditor() void SinglePopupEditor::testPopup() { - if(m_pTestPopup)delete m_pTestPopup; + if(m_pTestPopup) + delete m_pTestPopup; m_pTestPopup = getMenu(); - if(!m_pTestPopup)return; - connect(m_pTestPopup,SIGNAL(testModeItemClicked(KviKvsPopupMenuItem *)),this,SLOT(testModeMenuItemClicked(KviKvsPopupMenuItem *))); - QPoint pnt = m_pMenuButton->mapToGlobal(QPoint(0,m_pMenuButton->height())); + if(!m_pTestPopup) + return; + connect(m_pTestPopup, SIGNAL(testModeItemClicked(KviKvsPopupMenuItem *)), this, SLOT(testModeMenuItemClicked(KviKvsPopupMenuItem *))); + QPoint pnt = m_pMenuButton->mapToGlobal(QPoint(0, m_pMenuButton->height())); KviKvsVariantList * parms = new KviKvsVariantList(); parms->append(new KviKvsVariant(QString("test1"))); parms->append(new KviKvsVariant(QString("test2"))); parms->append(new KviKvsVariant(QString("test3"))); parms->append(new KviKvsVariant(QString("test4"))); - m_pTestPopup->doPopup(pnt,g_pActiveWindow,parms,true); + m_pTestPopup->doPopup(pnt, g_pActiveWindow, parms, true); } -PopupTreeWidgetItem * SinglePopupEditor::findMatchingItem(KviKvsPopupMenuItem * it,PopupTreeWidgetItem * item) +PopupTreeWidgetItem * SinglePopupEditor::findMatchingItem(KviKvsPopupMenuItem * it, PopupTreeWidgetItem * item) { - if(it->type() != KviKvsPopupMenuItem::Item)goto not_this_one; - if(item->m_type != PopupTreeWidgetItem::Item)goto not_this_one; - if(it->name() != item->m_szId)goto not_this_one; + if(it->type() != KviKvsPopupMenuItem::Item) + goto not_this_one; + if(item->m_type != PopupTreeWidgetItem::Item) + goto not_this_one; + if(it->name() != item->m_szId) + goto not_this_one; if(it->kvsText()) { - if(it->kvsText()->code() != item->m_szText)goto not_this_one; - } else { - if(!item->m_szText.isEmpty())goto not_this_one; + if(it->kvsText()->code() != item->m_szText) + goto not_this_one; + } + else + { + if(!item->m_szText.isEmpty()) + goto not_this_one; } if(it->kvsCode()) { - if(it->kvsCode()->code() != item->m_szCode)goto not_this_one; - } else { - if(!item->m_szCode.isEmpty())goto not_this_one; + if(it->kvsCode()->code() != item->m_szCode) + goto not_this_one; + } + else + { + if(!item->m_szCode.isEmpty()) + goto not_this_one; } if(it->kvsIcon()) { - if(it->kvsIcon()->code() != item->m_szIcon)goto not_this_one; - } else { - if(!item->m_szIcon.isEmpty())goto not_this_one; + if(it->kvsIcon()->code() != item->m_szIcon) + goto not_this_one; + } + else + { + if(!item->m_szIcon.isEmpty()) + goto not_this_one; } if(it->kvsCondition()) { - if(it->kvsCondition()->code() != item->m_szCondition)goto not_this_one; - } else { - if(!item->m_szCondition.isEmpty())goto not_this_one; + if(it->kvsCondition()->code() != item->m_szCondition) + goto not_this_one; + } + else + { + if(!item->m_szCondition.isEmpty()) + goto not_this_one; } return item; not_this_one: - int count=item->childCount(); - for(int i=0; i<count; i++) + int count = item->childCount(); + for(int i = 0; i < count; i++) { item = (PopupTreeWidgetItem *)item->child(i); - PopupTreeWidgetItem * found = findMatchingItem(it,item); - if(found)return found; + PopupTreeWidgetItem * found = findMatchingItem(it, item); + if(found) + return found; } return 0; @@ -346,11 +363,11 @@ void SinglePopupEditor::testModeMenuItemClicked(KviKvsPopupMenuItem * it) saveLastSelectedItem(); // that's the first thingie // find the matching item and set it as current - int count=m_pTreeWidget->topLevelItemCount(); - for(int i=0; i<count; i++) + int count = m_pTreeWidget->topLevelItemCount(); + for(int i = 0; i < count; i++) { PopupTreeWidgetItem * item = (PopupTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); - PopupTreeWidgetItem * found = findMatchingItem(it,item); + PopupTreeWidgetItem * found = findMatchingItem(it, item); if(found) { // set the item as current @@ -361,12 +378,11 @@ void SinglePopupEditor::testModeMenuItemClicked(KviKvsPopupMenuItem * it) return; } } - } -void SinglePopupEditor::customContextMenuRequested(const QPoint &pos) +void SinglePopupEditor::customContextMenuRequested(const QPoint & pos) { - QTreeWidgetItem *it=m_pTreeWidget->itemAt(pos); + QTreeWidgetItem * it = m_pTreeWidget->itemAt(pos); m_pContextPopup->clear(); @@ -379,106 +395,108 @@ void SinglePopupEditor::customContextMenuRequested(const QPoint &pos) bIsMenu = ((PopupTreeWidgetItem *)it)->m_type == PopupTreeWidgetItem::Menu; } - m_pContextPopup->addAction(__tr2qs_ctx("New Separator Below","editor"),this,SLOT(contextNewSeparatorBelow())); - m_pContextPopup->addAction(__tr2qs_ctx("New Separator Above","editor"),this,SLOT(contextNewSeparatorAbove())) - ->setEnabled(it); - m_pContextPopup->addAction(__tr2qs_ctx("New Separator Inside","editor"),this,SLOT(contextNewSeparatorInside())) - ->setEnabled(it && bIsMenu); + m_pContextPopup->addAction(__tr2qs_ctx("New Separator Below", "editor"), this, SLOT(contextNewSeparatorBelow())); + m_pContextPopup->addAction(__tr2qs_ctx("New Separator Above", "editor"), this, SLOT(contextNewSeparatorAbove())) + ->setEnabled(it); + m_pContextPopup->addAction(__tr2qs_ctx("New Separator Inside", "editor"), this, SLOT(contextNewSeparatorInside())) + ->setEnabled(it && bIsMenu); m_pContextPopup->addSeparator(); - m_pContextPopup->addAction(__tr2qs_ctx("New Label Below","editor"),this,SLOT(contextNewLabelBelow())); - m_pContextPopup->addAction(__tr2qs_ctx("New Label Above","editor"),this,SLOT(contextNewLabelAbove())) - ->setEnabled(it); - m_pContextPopup->addAction(__tr2qs_ctx("New Label Inside","editor"),this,SLOT(contextNewLabelInside())) - ->setEnabled(it && bIsMenu); + m_pContextPopup->addAction(__tr2qs_ctx("New Label Below", "editor"), this, SLOT(contextNewLabelBelow())); + m_pContextPopup->addAction(__tr2qs_ctx("New Label Above", "editor"), this, SLOT(contextNewLabelAbove())) + ->setEnabled(it); + m_pContextPopup->addAction(__tr2qs_ctx("New Label Inside", "editor"), this, SLOT(contextNewLabelInside())) + ->setEnabled(it && bIsMenu); m_pContextPopup->addSeparator(); - m_pContextPopup->addAction(__tr2qs_ctx("New Item Below","editor"),this,SLOT(contextNewItemBelow())); - m_pContextPopup->addAction(__tr2qs_ctx("New Item Above","editor"),this,SLOT(contextNewItemAbove())) - ->setEnabled(it); - m_pContextPopup->addAction(__tr2qs_ctx("New Item Inside","editor"),this,SLOT(contextNewItemInside())) - ->setEnabled(it && bIsMenu); + m_pContextPopup->addAction(__tr2qs_ctx("New Item Below", "editor"), this, SLOT(contextNewItemBelow())); + m_pContextPopup->addAction(__tr2qs_ctx("New Item Above", "editor"), this, SLOT(contextNewItemAbove())) + ->setEnabled(it); + m_pContextPopup->addAction(__tr2qs_ctx("New Item Inside", "editor"), this, SLOT(contextNewItemInside())) + ->setEnabled(it && bIsMenu); m_pContextPopup->addSeparator(); - m_pContextPopup->addAction(__tr2qs_ctx("New Menu Below","editor"),this,SLOT(contextNewMenuBelow())); - m_pContextPopup->addAction(__tr2qs_ctx("New Menu Above","editor"),this,SLOT(contextNewMenuAbove())) - ->setEnabled(it); - m_pContextPopup->addAction(__tr2qs_ctx("New Menu Inside","editor"),this,SLOT(contextNewMenuInside())) - ->setEnabled(it && bIsMenu); + m_pContextPopup->addAction(__tr2qs_ctx("New Menu Below", "editor"), this, SLOT(contextNewMenuBelow())); + m_pContextPopup->addAction(__tr2qs_ctx("New Menu Above", "editor"), this, SLOT(contextNewMenuAbove())) + ->setEnabled(it); + m_pContextPopup->addAction(__tr2qs_ctx("New Menu Inside", "editor"), this, SLOT(contextNewMenuInside())) + ->setEnabled(it && bIsMenu); m_pContextPopup->addSeparator(); - m_pContextPopup->addAction(__tr2qs_ctx("New External Menu Below","editor"),this,SLOT(contextNewExtMenuBelow())); - m_pContextPopup->addAction(__tr2qs_ctx("New External Menu Above","editor"),this,SLOT(contextNewExtMenuAbove())) - ->setEnabled(it); - m_pContextPopup->addAction(__tr2qs_ctx("New External Menu Inside","editor"),this,SLOT(contextNewExtMenuInside())) - ->setEnabled(it && bIsMenu); + m_pContextPopup->addAction(__tr2qs_ctx("New External Menu Below", "editor"), this, SLOT(contextNewExtMenuBelow())); + m_pContextPopup->addAction(__tr2qs_ctx("New External Menu Above", "editor"), this, SLOT(contextNewExtMenuAbove())) + ->setEnabled(it); + m_pContextPopup->addAction(__tr2qs_ctx("New External Menu Inside", "editor"), this, SLOT(contextNewExtMenuInside())) + ->setEnabled(it && bIsMenu); m_pContextPopup->addSeparator(); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Cut)), - __tr2qs_ctx("Cu&t","editor"),this,SLOT(contextCut())) - ->setEnabled(it); + *(g_pIconManager->getSmallIcon(KviIconManager::Cut)), + __tr2qs_ctx("Cu&t", "editor"), this, SLOT(contextCut())) + ->setEnabled(it); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Copy)), - __tr2qs_ctx("&Copy","editor"),this,SLOT(contextCopy())) - ->setEnabled(it); + *(g_pIconManager->getSmallIcon(KviIconManager::Copy)), + __tr2qs_ctx("&Copy", "editor"), this, SLOT(contextCopy())) + ->setEnabled(it); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Discard)), - __tr2qs_ctx("Re&move","editor"),this,SLOT(contextRemove())) - ->setEnabled(it); + *(g_pIconManager->getSmallIcon(KviIconManager::Discard)), + __tr2qs_ctx("Re&move", "editor"), this, SLOT(contextRemove())) + ->setEnabled(it); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Paste)), - __tr2qs_ctx("&Paste Below","editor"),this,SLOT(contextPasteBelow())) - ->setEnabled(m_pClipboard); + *(g_pIconManager->getSmallIcon(KviIconManager::Paste)), + __tr2qs_ctx("&Paste Below", "editor"), this, SLOT(contextPasteBelow())) + ->setEnabled(m_pClipboard); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Paste)), - __tr2qs_ctx("Paste Above","editor"),this,SLOT(contextPasteAbove())) - ->setEnabled(it && m_pClipboard); + *(g_pIconManager->getSmallIcon(KviIconManager::Paste)), + __tr2qs_ctx("Paste Above", "editor"), this, SLOT(contextPasteAbove())) + ->setEnabled(it && m_pClipboard); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Paste)), - __tr2qs_ctx("Paste Inside","editor"),this,SLOT(contextPasteInside())) - ->setEnabled(it && bIsMenu && m_pClipboard); + *(g_pIconManager->getSmallIcon(KviIconManager::Paste)), + __tr2qs_ctx("Paste Inside", "editor"), this, SLOT(contextPasteInside())) + ->setEnabled(it && bIsMenu && m_pClipboard); bool bSeparatorInserted = false; -// if(!findPrologue(parentMenu)) -// { + // if(!findPrologue(parentMenu)) + // { m_pContextPopup->addSeparator(); bSeparatorInserted = true; m_pContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Prologue)), - __tr2qs_ctx("New Menu Prologue","editor"),this,SLOT(contextNewPrologue())); -// } + __tr2qs_ctx("New Menu Prologue", "editor"), this, SLOT(contextNewPrologue())); + // } -// if(!findEpilogue(parentMenu)) -// { - if(!bSeparatorInserted)m_pContextPopup->addSeparator(); + // if(!findEpilogue(parentMenu)) + // { + if(!bSeparatorInserted) + m_pContextPopup->addSeparator(); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Epilogue)), - __tr2qs_ctx("New Menu Epilogue","editor"),this,SLOT(contextNewEpilogue())); -// } + *(g_pIconManager->getSmallIcon(KviIconManager::Epilogue)), + __tr2qs_ctx("New Menu Epilogue", "editor"), this, SLOT(contextNewEpilogue())); + // } m_pContextPopup->popup(QCursor::pos()); } void SinglePopupEditor::createNewItemAboveLastSelected(PopupTreeWidgetItem::Type t) { - m_pTreeWidget->setCurrentItem(newItemAbove(m_pLastSelectedItem,t)); + m_pTreeWidget->setCurrentItem(newItemAbove(m_pLastSelectedItem, t)); } void SinglePopupEditor::createNewItemBelowLastSelected(PopupTreeWidgetItem::Type t) { - m_pTreeWidget->setCurrentItem(newItemBelow(m_pLastSelectedItem,t)); + m_pTreeWidget->setCurrentItem(newItemBelow(m_pLastSelectedItem, t)); } void SinglePopupEditor::createNewItemInsideLastSelected(PopupTreeWidgetItem::Type t) { - if(m_pLastSelectedItem)m_pLastSelectedItem->setExpanded(true); - m_pTreeWidget->setCurrentItem(newItemInside(m_pLastSelectedItem,t)); + if(m_pLastSelectedItem) + m_pLastSelectedItem->setExpanded(true); + m_pTreeWidget->setCurrentItem(newItemInside(m_pLastSelectedItem, t)); } void SinglePopupEditor::contextNewSeparatorAbove() @@ -555,76 +573,84 @@ void SinglePopupEditor::contextNewLabelInside() createNewItemInsideLastSelected(PopupTreeWidgetItem::Label); } -PopupTreeWidgetItem * SinglePopupEditor::newItem(PopupTreeWidgetItem * par,PopupTreeWidgetItem * after,PopupTreeWidgetItem::Type t) +PopupTreeWidgetItem * SinglePopupEditor::newItem(PopupTreeWidgetItem * par, PopupTreeWidgetItem * after, PopupTreeWidgetItem::Type t) { - if(par)return new PopupTreeWidgetItem(par,after,t); - return new PopupTreeWidgetItem(m_pTreeWidget,after,t); + if(par) + return new PopupTreeWidgetItem(par, after, t); + return new PopupTreeWidgetItem(m_pTreeWidget, after, t); } -PopupTreeWidgetItem * SinglePopupEditor::newItemBelow(PopupTreeWidgetItem * it,PopupTreeWidgetItem::Type t) +PopupTreeWidgetItem * SinglePopupEditor::newItemBelow(PopupTreeWidgetItem * it, PopupTreeWidgetItem::Type t) { - if(!it)return newItem(0,0,t); - return newItem((PopupTreeWidgetItem *)it->parent(),it,t); + if(!it) + return newItem(0, 0, t); + return newItem((PopupTreeWidgetItem *)it->parent(), it, t); } -PopupTreeWidgetItem * SinglePopupEditor::newItemAbove(PopupTreeWidgetItem * it,PopupTreeWidgetItem::Type t) +PopupTreeWidgetItem * SinglePopupEditor::newItemAbove(PopupTreeWidgetItem * it, PopupTreeWidgetItem::Type t) { - if(!it)return newItem(0,0,t); - return newItem((PopupTreeWidgetItem *)it->parent(),(PopupTreeWidgetItem *)m_pTreeWidget->itemAbove(it),t); + if(!it) + return newItem(0, 0, t); + return newItem((PopupTreeWidgetItem *)it->parent(), (PopupTreeWidgetItem *)m_pTreeWidget->itemAbove(it), t); } -PopupTreeWidgetItem * SinglePopupEditor::newItemInside(PopupTreeWidgetItem * it,PopupTreeWidgetItem::Type t) +PopupTreeWidgetItem * SinglePopupEditor::newItemInside(PopupTreeWidgetItem * it, PopupTreeWidgetItem::Type t) { if(it) { if(it->m_type != PopupTreeWidgetItem::Menu) { - return newItemBelow(it,t); + return newItemBelow(it, t); } } - return newItem(it,it,t); + return newItem(it, it, t); } void SinglePopupEditor::contextNewPrologue() { PopupTreeWidgetItem * it = m_pLastSelectedItem ? (PopupTreeWidgetItem *)m_pLastSelectedItem->parent() : 0; -// if(!findPrologue(it)) -// { - m_pTreeWidget->setCurrentItem(newItem(it,it,PopupTreeWidgetItem::Prologue)); -// } + // if(!findPrologue(it)) + // { + m_pTreeWidget->setCurrentItem(newItem(it, it, PopupTreeWidgetItem::Prologue)); + // } } void SinglePopupEditor::contextNewEpilogue() { PopupTreeWidgetItem * it = m_pLastSelectedItem ? (PopupTreeWidgetItem *)m_pLastSelectedItem->parent() : 0; -// if(!findEpilogue(it)) -// { + // if(!findEpilogue(it)) + // { PopupTreeWidgetItem * after = it ? (PopupTreeWidgetItem *)it->child(0) : (PopupTreeWidgetItem *)m_pTreeWidget->topLevelItem(0); if(after) { while(m_pTreeWidget->itemAbove(after)) { - if(after->parent()==m_pTreeWidget->itemAbove(after)->parent()) + if(after->parent() == m_pTreeWidget->itemAbove(after)->parent()) after = (PopupTreeWidgetItem *)m_pTreeWidget->itemAbove(after); } - } else { + } + else + { after = it; } - m_pTreeWidget->setCurrentItem(newItem(it,after,PopupTreeWidgetItem::Epilogue)); -// } + m_pTreeWidget->setCurrentItem(newItem(it, after, PopupTreeWidgetItem::Epilogue)); + // } } void SinglePopupEditor::contextCopy() { - if(!m_pLastSelectedItem)return; - if(m_pClipboard)delete m_pClipboard; + if(!m_pLastSelectedItem) + return; + if(m_pClipboard) + delete m_pClipboard; m_pClipboard = new KviKvsPopupMenu("clipboard"); - addItemToMenu(m_pClipboard,m_pLastSelectedItem); + addItemToMenu(m_pClipboard, m_pLastSelectedItem); } void SinglePopupEditor::contextCut() { - if(!m_pLastSelectedItem)return; + if(!m_pLastSelectedItem) + return; contextCopy(); delete m_pLastSelectedItem; @@ -634,7 +660,8 @@ void SinglePopupEditor::contextCut() void SinglePopupEditor::contextRemove() { - if(!m_pLastSelectedItem)return; + if(!m_pLastSelectedItem) + return; delete m_pLastSelectedItem; m_pLastSelectedItem = nullptr; @@ -643,22 +670,25 @@ void SinglePopupEditor::contextRemove() void SinglePopupEditor::contextPasteBelow() { - if(!m_pClipboard)return; + if(!m_pClipboard) + return; PopupTreeWidgetItem * par = m_pLastSelectedItem ? (PopupTreeWidgetItem *)m_pLastSelectedItem->parent() : 0; - populateMenu(m_pClipboard,par,m_pLastSelectedItem); + populateMenu(m_pClipboard, par, m_pLastSelectedItem); } void SinglePopupEditor::contextPasteAbove() { - if(!m_pClipboard)return; + if(!m_pClipboard) + return; PopupTreeWidgetItem * par = m_pLastSelectedItem ? (PopupTreeWidgetItem *)m_pLastSelectedItem->parent() : 0; PopupTreeWidgetItem * above = m_pLastSelectedItem ? (PopupTreeWidgetItem *)m_pTreeWidget->itemAbove(m_pLastSelectedItem) : 0; - populateMenu(m_pClipboard,par,above); + populateMenu(m_pClipboard, par, above); } void SinglePopupEditor::contextPasteInside() { - if(!m_pClipboard)return; + if(!m_pClipboard) + return; if(m_pLastSelectedItem) { if(m_pLastSelectedItem->m_type != PopupTreeWidgetItem::Menu) @@ -668,12 +698,13 @@ void SinglePopupEditor::contextPasteInside() } m_pLastSelectedItem->setExpanded(true); } - populateMenu(m_pClipboard,m_pLastSelectedItem,0); + populateMenu(m_pClipboard, m_pLastSelectedItem, 0); } void SinglePopupEditor::saveLastSelectedItem() { - if(!m_pLastSelectedItem)return; + if(!m_pLastSelectedItem) + return; QString tmp; @@ -689,7 +720,7 @@ void SinglePopupEditor::saveLastSelectedItem() } break; default: - break; + break; } m_pLastSelectedItem->setId(m_pIdEditor->text()); @@ -700,9 +731,9 @@ void SinglePopupEditor::saveLastSelectedItem() case PopupTreeWidgetItem::ExtMenu: case PopupTreeWidgetItem::Item: m_pLastSelectedItem->setIcon(m_pIconEditor->text()); - break; + break; default: - break; + break; } switch(m_pLastSelectedItem->m_type) @@ -712,9 +743,9 @@ void SinglePopupEditor::saveLastSelectedItem() case PopupTreeWidgetItem::Label: case PopupTreeWidgetItem::ExtMenu: m_pLastSelectedItem->setItemText(m_pTextEditor->text()); - break; + break; default: - break; + break; } switch(m_pLastSelectedItem->m_type) @@ -725,9 +756,9 @@ void SinglePopupEditor::saveLastSelectedItem() case PopupTreeWidgetItem::ExtMenu: case PopupTreeWidgetItem::Separator: m_pLastSelectedItem->setCondition(m_pConditionEditor->text()); - break; + break; default: - break; + break; } if(m_pLastSelectedItem->m_type == PopupTreeWidgetItem::ExtMenu) @@ -736,58 +767,58 @@ void SinglePopupEditor::saveLastSelectedItem() } } -void SinglePopupEditor::addItemToMenu(KviKvsPopupMenu * p,PopupTreeWidgetItem *it) +void SinglePopupEditor::addItemToMenu(KviKvsPopupMenu * p, PopupTreeWidgetItem * it) { it->m_szId = it->m_szId.trimmed(); switch(it->m_type) { case PopupTreeWidgetItem::Prologue: it->m_szCode = it->m_szCode.trimmed(); - p->addPrologue(it->m_szId,it->m_szCode); - break; + p->addPrologue(it->m_szId, it->m_szCode); + break; case PopupTreeWidgetItem::Epilogue: it->m_szCode = it->m_szCode.trimmed(); - p->addEpilogue(it->m_szId,it->m_szCode); - break; + p->addEpilogue(it->m_szId, it->m_szCode); + break; case PopupTreeWidgetItem::Separator: it->m_szCondition = it->m_szCondition.trimmed(); - p->addSeparator(it->m_szId,it->m_szCondition); - break; + p->addSeparator(it->m_szId, it->m_szCondition); + break; case PopupTreeWidgetItem::Label: it->m_szText = it->m_szText.trimmed(); it->m_szCondition = it->m_szCondition.trimmed(); it->m_szIcon = it->m_szIcon.trimmed(); - p->addLabel(it->m_szId,it->m_szText,it->m_szIcon,it->m_szCondition); - break; + p->addLabel(it->m_szId, it->m_szText, it->m_szIcon, it->m_szCondition); + break; case PopupTreeWidgetItem::Item: it->m_szText = it->m_szText.trimmed(); it->m_szIcon = it->m_szIcon.trimmed(); it->m_szCondition = it->m_szCondition.trimmed(); it->m_szCode = it->m_szCode.trimmed(); - p->addItem(it->m_szId,it->m_szCode,it->m_szText,it->m_szIcon,it->m_szCondition); - break; + p->addItem(it->m_szId, it->m_szCode, it->m_szText, it->m_szIcon, it->m_szCondition); + break; case PopupTreeWidgetItem::ExtMenu: it->m_szText = it->m_szText.trimmed(); it->m_szIcon = it->m_szIcon.trimmed(); it->m_szCondition = it->m_szCondition.trimmed(); - it->m_szCode = it->m_szCode.trimmed();// <-- this is the ext name in fact - p->addExtPopup(it->m_szId,it->m_szCode,it->m_szText,it->m_szIcon,it->m_szCondition); - break; + it->m_szCode = it->m_szCode.trimmed(); // <-- this is the ext name in fact + p->addExtPopup(it->m_szId, it->m_szCode, it->m_szText, it->m_szIcon, it->m_szCondition); + break; case PopupTreeWidgetItem::Menu: { it->m_szText = it->m_szText.trimmed(); it->m_szIcon = it->m_szIcon.trimmed(); it->m_szCondition = it->m_szCondition.trimmed(); - KviKvsPopupMenu * menu = p->addPopup(it->m_szId,it->m_szText,it->m_szIcon,it->m_szCondition); - int count= it->childCount(); - for(int i=0; i<count; i++) + KviKvsPopupMenu * menu = p->addPopup(it->m_szId, it->m_szText, it->m_szIcon, it->m_szCondition); + int count = it->childCount(); + for(int i = 0; i < count; i++) { - addItemToMenu(menu,(PopupTreeWidgetItem *)it->child(i)); + addItemToMenu(menu, (PopupTreeWidgetItem *)it->child(i)); } } break; default: - break; + break; } } @@ -799,10 +830,10 @@ KviKvsPopupMenu * SinglePopupEditor::getMenu() KviKvsPopupMenu * p = new KviKvsPopupMenu(tmp); - int count= m_pTreeWidget->topLevelItemCount(); - for(int i=0; i<count; i++) + int count = m_pTreeWidget->topLevelItemCount(); + for(int i = 0; i < count; i++) { - addItemToMenu(p,(PopupTreeWidgetItem *)m_pTreeWidget->topLevelItem(i)); + addItemToMenu(p, (PopupTreeWidgetItem *)m_pTreeWidget->topLevelItem(i)); } return p; } @@ -821,9 +852,11 @@ void SinglePopupEditor::selectionChanged() if(m_pTreeWidget->selectedItems().empty()) { - it=0; - } else { - it= (QTreeWidgetItem*)m_pTreeWidget->selectedItems().first(); + it = 0; + } + else + { + it = (QTreeWidgetItem *)m_pTreeWidget->selectedItems().first(); } if(it) @@ -837,9 +870,9 @@ void SinglePopupEditor::selectionChanged() case PopupTreeWidgetItem::Item: m_pEditor->setText(((PopupTreeWidgetItem *)it)->m_szCode); bEditorEnabled = true; - break; + break; default: - break; + break; } switch(((PopupTreeWidgetItem *)it)->m_type) @@ -850,9 +883,10 @@ void SinglePopupEditor::selectionChanged() case PopupTreeWidgetItem::ExtMenu: m_pIconEditor->setText(((PopupTreeWidgetItem *)it)->m_szIcon); bIconEditorEnabled = true; - break; + break; default: - break; } + break; + } switch(((PopupTreeWidgetItem *)it)->m_type) { @@ -862,9 +896,9 @@ void SinglePopupEditor::selectionChanged() case PopupTreeWidgetItem::ExtMenu: m_pTextEditor->setText(((PopupTreeWidgetItem *)it)->m_szText); bTextEditorEnabled = true; - break; + break; default: - break; + break; } switch(((PopupTreeWidgetItem *)it)->m_type) @@ -876,100 +910,121 @@ void SinglePopupEditor::selectionChanged() case PopupTreeWidgetItem::Separator: m_pConditionEditor->setText(((PopupTreeWidgetItem *)it)->m_szCondition); bConditionEditorEnabled = true; - break; + break; default: - break; + break; } if(((PopupTreeWidgetItem *)it)->m_type == PopupTreeWidgetItem::ExtMenu) { m_pExtNameEditor->setText(((PopupTreeWidgetItem *)it)->m_szCode); - bNameEditorEnabled =true; + bNameEditorEnabled = true; } } m_pLastSelectedItem = (PopupTreeWidgetItem *)it; - if(!bEditorEnabled)m_pEditor->setText(""); + if(!bEditorEnabled) + m_pEditor->setText(""); m_pEditor->setEnabled(bEditorEnabled); - if(!bIconEditorEnabled)m_pIconEditor->setText(""); + if(!bIconEditorEnabled) + m_pIconEditor->setText(""); m_pIconEditor->setEnabled(bIconEditorEnabled); - if(!bConditionEditorEnabled)m_pConditionEditor->setText(""); + if(!bConditionEditorEnabled) + m_pConditionEditor->setText(""); m_pConditionEditor->setEnabled(bConditionEditorEnabled); - if(!bTextEditorEnabled)m_pTextEditor->setText(""); + if(!bTextEditorEnabled) + m_pTextEditor->setText(""); m_pTextEditor->setEnabled(bTextEditorEnabled); m_pExtNameEditor->setEnabled(bNameEditorEnabled); - if(!bNameEditorEnabled)m_pExtNameEditor->setText(""); - if(!it)m_pIdEditor->setText(""); + if(!bNameEditorEnabled) + m_pExtNameEditor->setText(""); + if(!it) + m_pIdEditor->setText(""); m_pIdEditor->setEnabled(it); } -void SinglePopupEditor::populateMenu(KviKvsPopupMenu * pop,PopupTreeWidgetItem * par,PopupTreeWidgetItem * theItem) +void SinglePopupEditor::populateMenu(KviKvsPopupMenu * pop, PopupTreeWidgetItem * par, PopupTreeWidgetItem * theItem) { - if(!pop)return; + if(!pop) + return; - for(KviKvsScript * sp = pop->prologues()->first();sp;sp = pop->prologues()->next()) + for(KviKvsScript * sp = pop->prologues()->first(); sp; sp = pop->prologues()->next()) { - if(par)theItem = new PopupTreeWidgetItem(par,theItem,PopupTreeWidgetItem::Prologue); - else theItem = new PopupTreeWidgetItem(m_pTreeWidget,theItem,PopupTreeWidgetItem::Prologue); + if(par) + theItem = new PopupTreeWidgetItem(par, theItem, PopupTreeWidgetItem::Prologue); + else + theItem = new PopupTreeWidgetItem(m_pTreeWidget, theItem, PopupTreeWidgetItem::Prologue); theItem->setCode(sp->code()); theItem->setId(sp->name()); } - for(KviKvsPopupMenuItem * item = pop->itemList()->first();item;item = pop->itemList()->next()) + for(KviKvsPopupMenuItem * item = pop->itemList()->first(); item; item = pop->itemList()->next()) { switch(item->type()) { case KviKvsPopupMenuItem::Item: - if(par)theItem = new PopupTreeWidgetItem(par,theItem,PopupTreeWidgetItem::Item); - else theItem = new PopupTreeWidgetItem(m_pTreeWidget,theItem,PopupTreeWidgetItem::Item); + if(par) + theItem = new PopupTreeWidgetItem(par, theItem, PopupTreeWidgetItem::Item); + else + theItem = new PopupTreeWidgetItem(m_pTreeWidget, theItem, PopupTreeWidgetItem::Item); theItem->setIcon(item->kvsIcon() ? item->kvsIcon()->code() : QString()); theItem->setItemText(item->kvsText() ? item->kvsText()->code() : QString()); theItem->setCondition(item->kvsCondition() ? item->kvsCondition()->code() : QString()); theItem->setCode(item->kvsCode() ? item->kvsCode()->code() : QString()); theItem->setId(item->name()); - break; + break; case KviKvsPopupMenuItem::ExtMenu: - if(par)theItem = new PopupTreeWidgetItem(par,theItem,PopupTreeWidgetItem::ExtMenu); - else theItem = new PopupTreeWidgetItem(m_pTreeWidget,theItem,PopupTreeWidgetItem::ExtMenu); + if(par) + theItem = new PopupTreeWidgetItem(par, theItem, PopupTreeWidgetItem::ExtMenu); + else + theItem = new PopupTreeWidgetItem(m_pTreeWidget, theItem, PopupTreeWidgetItem::ExtMenu); theItem->setIcon(item->kvsIcon() ? item->kvsIcon()->code() : QString()); theItem->setItemText(item->kvsText() ? item->kvsText()->code() : QString()); theItem->setCondition(item->kvsCondition() ? item->kvsCondition()->code() : QString()); theItem->setCode(((KviKvsPopupMenuItemExtMenu *)item)->extName()); theItem->setId(item->name()); - break; + break; case KviKvsPopupMenuItem::Label: - if(par)theItem = new PopupTreeWidgetItem(par,theItem,PopupTreeWidgetItem::Label); - else theItem = new PopupTreeWidgetItem(m_pTreeWidget,theItem,PopupTreeWidgetItem::Label); + if(par) + theItem = new PopupTreeWidgetItem(par, theItem, PopupTreeWidgetItem::Label); + else + theItem = new PopupTreeWidgetItem(m_pTreeWidget, theItem, PopupTreeWidgetItem::Label); theItem->setIcon(item->kvsIcon() ? item->kvsIcon()->code() : QString()); theItem->setItemText(item->kvsText() ? item->kvsText()->code() : QString()); theItem->setCondition(item->kvsCondition() ? item->kvsCondition()->code() : QString()); theItem->setId(item->name()); - break; + break; case KviKvsPopupMenuItem::Separator: - if(par)theItem = new PopupTreeWidgetItem(par,theItem,PopupTreeWidgetItem::Separator); - else theItem = new PopupTreeWidgetItem(m_pTreeWidget,theItem,PopupTreeWidgetItem::Separator); + if(par) + theItem = new PopupTreeWidgetItem(par, theItem, PopupTreeWidgetItem::Separator); + else + theItem = new PopupTreeWidgetItem(m_pTreeWidget, theItem, PopupTreeWidgetItem::Separator); theItem->setCondition(item->kvsCondition() ? item->kvsCondition()->code() : QString()); theItem->setId(item->name()); - break; + break; case KviKvsPopupMenuItem::Menu: - if(par)theItem = new PopupTreeWidgetItem(par,theItem,PopupTreeWidgetItem::Menu); - else theItem = new PopupTreeWidgetItem(m_pTreeWidget,theItem,PopupTreeWidgetItem::Menu); + if(par) + theItem = new PopupTreeWidgetItem(par, theItem, PopupTreeWidgetItem::Menu); + else + theItem = new PopupTreeWidgetItem(m_pTreeWidget, theItem, PopupTreeWidgetItem::Menu); theItem->setIcon(item->kvsIcon() ? item->kvsIcon()->code() : QString()); theItem->setItemText(item->kvsText() ? item->kvsText()->code() : QString()); theItem->setCondition(item->kvsCondition() ? item->kvsCondition()->code() : QString()); theItem->setId(item->name()); - populateMenu(((KviKvsPopupMenuItemMenu *)item)->menu(),theItem,0); - break; + populateMenu(((KviKvsPopupMenuItemMenu *)item)->menu(), theItem, 0); + break; default: - break; + break; } } - for(KviKvsScript * se = pop->epilogues()->first();se;se = pop->epilogues()->next()) + for(KviKvsScript * se = pop->epilogues()->first(); se; se = pop->epilogues()->next()) { - if(par)theItem = new PopupTreeWidgetItem(par,theItem,PopupTreeWidgetItem::Epilogue); - else theItem = new PopupTreeWidgetItem(m_pTreeWidget,theItem,PopupTreeWidgetItem::Epilogue); + if(par) + theItem = new PopupTreeWidgetItem(par, theItem, PopupTreeWidgetItem::Epilogue); + else + theItem = new PopupTreeWidgetItem(m_pTreeWidget, theItem, PopupTreeWidgetItem::Epilogue); theItem->setCode(se->code()); theItem->setId(se->name()); } @@ -990,8 +1045,10 @@ void SinglePopupEditor::edit(MenuTreeWidgetItem * it) if(it) { m_pNameEditor->setText(it->m_pPopup->popupName()); - populateMenu(it->m_pPopup,0,0); - } else { + populateMenu(it->m_pPopup, 0, 0); + } + else + { m_pIconEditor->setText(""); m_pIconEditor->setEnabled(false); m_pIdEditor->setText(""); @@ -1009,15 +1066,13 @@ void SinglePopupEditor::edit(MenuTreeWidgetItem * it) m_pTreeWidget->setEnabled(it); m_pNameEditor->setEnabled(it); m_pMenuButton->setEnabled(it); - } - -MenuTreeWidgetItem::MenuTreeWidgetItem(QTreeWidget * par,KviKvsPopupMenu * popup) -: QTreeWidgetItem(par) +MenuTreeWidgetItem::MenuTreeWidgetItem(QTreeWidget * par, KviKvsPopupMenu * popup) + : QTreeWidgetItem(par) { - setIcon(0,*(g_pIconManager->getSmallIcon(KviIconManager::Popup))); - setText(0,popup->popupName()); + setIcon(0, *(g_pIconManager->getSmallIcon(KviIconManager::Popup))); + setText(0, popup->popupName()); m_pPopup = popup; } @@ -1033,27 +1088,27 @@ void MenuTreeWidgetItem::replacePopup(KviKvsPopupMenu * popup) } PopupEditorWidget::PopupEditorWidget(QWidget * par) -: QWidget(par) + : QWidget(par) { m_bSaving = false; QGridLayout * l = new QGridLayout(this); - QSplitter * spl = new QSplitter(Qt::Horizontal,this); + QSplitter * spl = new QSplitter(Qt::Horizontal, this); spl->setObjectName("popupeditor_horizontal_splitter"); spl->setChildrenCollapsible(false); - l->addWidget(spl,0,0); + l->addWidget(spl, 0, 0); KviTalVBox * box = new KviTalVBox(spl); m_pTreeWidget = new QTreeWidget(box); - m_pTreeWidget->setHeaderLabel(__tr2qs_ctx("Popup","editor")); + m_pTreeWidget->setHeaderLabel(__tr2qs_ctx("Popup", "editor")); m_pTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); m_pTreeWidget->header()->setSortIndicatorShown(true); - QPushButton * pb = new QPushButton(__tr2qs_ctx("&Export All to...","editor"),box); - connect(pb,SIGNAL(clicked()),this,SLOT(exportAll())); - QPushButton * gn = new QPushButton(__tr2qs_ctx("&Export Selected to...","editor"),box); - connect(gn,SIGNAL(clicked()),this,SLOT(exportSelected())); + QPushButton * pb = new QPushButton(__tr2qs_ctx("&Export All to...", "editor"), box); + connect(pb, SIGNAL(clicked()), this, SLOT(exportAll())); + QPushButton * gn = new QPushButton(__tr2qs_ctx("&Export Selected to...", "editor"), box); + connect(gn, SIGNAL(clicked()), this, SLOT(exportSelected())); m_pEditor = new SinglePopupEditor(spl); @@ -1063,10 +1118,10 @@ PopupEditorWidget::PopupEditorWidget(QWidget * par) m_pContextPopup = new QMenu(this); m_pEmptyContextPopup = new QMenu(this); - spl->setStretchFactor(0,20); - spl->setStretchFactor(1,80); + spl->setStretchFactor(0, 20); + spl->setStretchFactor(1, 80); - currentItemChanged(0,0); + currentItemChanged(0, 0); } PopupEditorWidget::~PopupEditorWidget() @@ -1075,61 +1130,66 @@ PopupEditorWidget::~PopupEditorWidget() void PopupEditorWidget::oneTimeSetup() { - if(m_bOneTimeSetupDone)return; + if(m_bOneTimeSetupDone) + return; m_bOneTimeSetupDone = true; - const KviPointerHashTable<QString,KviKvsPopupMenu> * a = KviKvsPopupManager::instance()->popupDict(); - if(!a)return; + const KviPointerHashTable<QString, KviKvsPopupMenu> * a = KviKvsPopupManager::instance()->popupDict(); + if(!a) + return; - KviPointerHashTableIterator<QString,KviKvsPopupMenu> it(*a); + KviPointerHashTableIterator<QString, KviKvsPopupMenu> it(*a); while(it.current()) { KviKvsPopupMenu * popup = it.current(); KviKvsPopupMenu * copy = new KviKvsPopupMenu(popup->popupName()); copy->copyFrom(popup); - new MenuTreeWidgetItem(m_pTreeWidget,copy); + new MenuTreeWidgetItem(m_pTreeWidget, copy); ++it; } m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(m_pTreeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *))); - connect(m_pTreeWidget,SIGNAL(customContextMenuRequested(const QPoint &)), - this,SLOT(customContextMenuRequested(const QPoint &))); - connect(KviKvsPopupManager::instance(),SIGNAL(popupRefresh(const QString &)),this,SLOT(popupRefresh(const QString &))); + connect(m_pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); + connect(m_pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(customContextMenuRequested(const QPoint &))); + connect(KviKvsPopupManager::instance(), SIGNAL(popupRefresh(const QString &)), this, SLOT(popupRefresh(const QString &))); } -void PopupEditorWidget::popupRefresh(const QString &szName) +void PopupEditorWidget::popupRefresh(const QString & szName) { if(m_bSaving) return; - KviPointerHashTable<QString,KviKvsPopupMenu> * pTable = KviKvsPopupManager::instance()->popupDict(); - if(!pTable) return; + KviPointerHashTable<QString, KviKvsPopupMenu> * pTable = KviKvsPopupManager::instance()->popupDict(); + if(!pTable) + return; KviKvsPopupMenu * pPopup = pTable->find(szName); - if(!pPopup) return; + if(!pPopup) + return; // if it already exists, replace its popup - for(int i=0; i<m_pTreeWidget->topLevelItemCount();i++) + for(int i = 0; i < m_pTreeWidget->topLevelItemCount(); i++) { MenuTreeWidgetItem * ch = (MenuTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); - if(KviQString::equalCI(szName,ch->m_pPopup->popupName())) + if(KviQString::equalCI(szName, ch->m_pPopup->popupName())) { - if(ch==m_pLastEditedItem) + if(ch == m_pLastEditedItem) { if( - QMessageBox::warning(0,__tr2qs_ctx("Confirm Overwriting Current - KVIrc","editor"), - __tr2qs_ctx("An external script has changed the popup you are currently editing. Do you want to accept the external changes?","editor"), - QMessageBox::Yes,QMessageBox::No|QMessageBox::Default|QMessageBox::Escape) != QMessageBox::Yes - ) return; + QMessageBox::warning(0, __tr2qs_ctx("Confirm Overwriting Current - KVIrc", "editor"), + __tr2qs_ctx("An external script has changed the popup you are currently editing. Do you want to accept the external changes?", "editor"), + QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape) + != QMessageBox::Yes) + return; } KviKvsPopupMenu * pCopy = new KviKvsPopupMenu(szName); pCopy->copyFrom(pPopup); ch->replacePopup(pCopy); //refresh current item - if(ch==m_pLastEditedItem) + if(ch == m_pLastEditedItem) m_pEditor->edit(m_pLastEditedItem); return; } @@ -1137,12 +1197,12 @@ void PopupEditorWidget::popupRefresh(const QString &szName) // create it KviKvsPopupMenu * pCopy = new KviKvsPopupMenu(szName); pCopy->copyFrom(pPopup); - new MenuTreeWidgetItem(m_pTreeWidget,pCopy); + new MenuTreeWidgetItem(m_pTreeWidget, pCopy); } -void PopupEditorWidget::customContextMenuRequested(const QPoint &pos) +void PopupEditorWidget::customContextMenuRequested(const QPoint & pos) { - QTreeWidgetItem *it=m_pTreeWidget->itemAt(pos); + QTreeWidgetItem * it = m_pTreeWidget->itemAt(pos); KVI_ASSERT(m_bOneTimeSetupDone); if(it) @@ -1150,67 +1210,73 @@ void PopupEditorWidget::customContextMenuRequested(const QPoint &pos) m_pContextPopup->clear(); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Popup)), - __tr2qs_ctx("&New Popup","editor"), - this,SLOT(newPopup())); + *(g_pIconManager->getSmallIcon(KviIconManager::Popup)), + __tr2qs_ctx("&New Popup", "editor"), + this, SLOT(newPopup())); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Discard)), - __tr2qs_ctx("Re&move Popup","editor"), - this,SLOT(removeCurrentPopup())) - ->setEnabled(it); + *(g_pIconManager->getSmallIcon(KviIconManager::Discard)), + __tr2qs_ctx("Re&move Popup", "editor"), + this, SLOT(removeCurrentPopup())) + ->setEnabled(it); m_pContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Save)), - __tr2qs_ctx("&Export Popup to...","editor"), - this,SLOT(exportCurrentPopup())) - ->setEnabled(it); + *(g_pIconManager->getSmallIcon(KviIconManager::Save)), + __tr2qs_ctx("&Export Popup to...", "editor"), + this, SLOT(exportCurrentPopup())) + ->setEnabled(it); m_pContextPopup->popup(QCursor::pos()); - } else { + } + else + { m_pEmptyContextPopup->clear(); m_pEmptyContextPopup->addAction( - *(g_pIconManager->getSmallIcon(KviIconManager::Popup)), - __tr2qs_ctx("&New Popup","editor"), - this,SLOT(newPopup())); + *(g_pIconManager->getSmallIcon(KviIconManager::Popup)), + __tr2qs_ctx("&New Popup", "editor"), + this, SLOT(newPopup())); m_pEmptyContextPopup->popup(QCursor::pos()); } } void PopupEditorWidget::exportCurrentPopup() { - if(!m_pLastEditedItem)return; + if(!m_pLastEditedItem) + return; saveLastEditedItem(); - if(!m_pLastEditedItem)return; + if(!m_pLastEditedItem) + return; QString szName = QDir::homePath(); - if(!szName.endsWith(QString(KVI_PATH_SEPARATOR)))szName += KVI_PATH_SEPARATOR; + if(!szName.endsWith(QString(KVI_PATH_SEPARATOR))) + szName += KVI_PATH_SEPARATOR; szName += m_pLastEditedItem->popup()->popupName(); szName += ".kvs"; QString szFile; - if(!KviFileDialog::askForSaveFileName(szFile,__tr2qs_ctx("Enter a Filename - KVIrc","editor"),szName,KVI_FILTER_SCRIPT,true,true,true,this))return; + if(!KviFileDialog::askForSaveFileName(szFile, __tr2qs_ctx("Enter a Filename - KVIrc", "editor"), szName, KVI_FILTER_SCRIPT, true, true, true, this)) + return; QString szOut; m_pLastEditedItem->popup()->generateDefPopup(szOut); - if(!KviFileUtils::writeFile(szFile,szOut)) + if(!KviFileUtils::writeFile(szFile, szOut)) { - QMessageBox::warning(this,__tr2qs_ctx("Writing to File Failed - KVIrc","editor"),__tr2qs_ctx("Unable to write to the popups file.","editor"),__tr2qs_ctx("OK","editor")); + QMessageBox::warning(this, __tr2qs_ctx("Writing to File Failed - KVIrc", "editor"), __tr2qs_ctx("Unable to write to the popups file.", "editor"), __tr2qs_ctx("OK", "editor")); } } void PopupEditorWidget::exportAll() { - bool bSelectedOnly=true; + bool bSelectedOnly = true; exportPopups(bSelectedOnly); } void PopupEditorWidget::exportSelected() { - bool bSelectedOnly=false; + bool bSelectedOnly = false; exportPopups(bSelectedOnly); } @@ -1219,12 +1285,12 @@ void PopupEditorWidget::exportPopups(bool bSelectedOnly) saveLastEditedItem(); QString out; - int count=0, topcount=m_pTreeWidget->topLevelItemCount(); + int count = 0, topcount = m_pTreeWidget->topLevelItemCount(); - for(int i=0; i<topcount;i++) + for(int i = 0; i < topcount; i++) { MenuTreeWidgetItem * it = (MenuTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); - if((it->isSelected()) || (bSelectedOnly == true) ) + if((it->isSelected()) || (bSelectedOnly == true)) { count++; QString tmp; @@ -1237,16 +1303,18 @@ void PopupEditorWidget::exportPopups(bool bSelectedOnly) return; QString szName = QDir::homePath(); - if(!szName.endsWith(QString(KVI_PATH_SEPARATOR)))szName += KVI_PATH_SEPARATOR; + if(!szName.endsWith(QString(KVI_PATH_SEPARATOR))) + szName += KVI_PATH_SEPARATOR; szName += "popups.kvs"; QString szFile; - if(!KviFileDialog::askForSaveFileName(szFile,__tr2qs_ctx("Enter a Filename - KVIrc","editor"),szName,KVI_FILTER_SCRIPT,true,true,true,this))return; + if(!KviFileDialog::askForSaveFileName(szFile, __tr2qs_ctx("Enter a Filename - KVIrc", "editor"), szName, KVI_FILTER_SCRIPT, true, true, true, this)) + return; - if(!KviFileUtils::writeFile(szFile,out)) + if(!KviFileUtils::writeFile(szFile, out)) { - QMessageBox::warning(this,__tr2qs_ctx("Writing to File Failed - KVIrc","editor"),__tr2qs_ctx("Unable to write to the popups file.","editor"),__tr2qs_ctx("OK","editor")); + QMessageBox::warning(this, __tr2qs_ctx("Writing to File Failed - KVIrc", "editor"), __tr2qs_ctx("Unable to write to the popups file.", "editor"), __tr2qs_ctx("OK", "editor")); } } @@ -1258,36 +1326,37 @@ void PopupEditorWidget::removeCurrentPopup() m_pLastEditedItem = nullptr; delete it; if(!m_pLastEditedItem) - currentItemChanged(0,0); + currentItemChanged(0, 0); } } void PopupEditorWidget::newPopup() { QString newName; - getUniquePopupName(0,newName); - MenuTreeWidgetItem * it = new MenuTreeWidgetItem(m_pTreeWidget,new KviKvsPopupMenu(newName)); + getUniquePopupName(0, newName); + MenuTreeWidgetItem * it = new MenuTreeWidgetItem(m_pTreeWidget, new KviKvsPopupMenu(newName)); m_pTreeWidget->setCurrentItem(it); } void PopupEditorWidget::saveLastEditedItem() { - if(!m_pLastEditedItem)return; + if(!m_pLastEditedItem) + return; KviKvsPopupMenu * m = m_pEditor->getMenu(); QString tmp = m->popupName(); QString old = m_pLastEditedItem->m_pPopup->popupName(); - if(!KviQString::equalCI(tmp,old)) + if(!KviQString::equalCI(tmp, old)) { - getUniquePopupName(m_pLastEditedItem,tmp); + getUniquePopupName(m_pLastEditedItem, tmp); m->setPopupName(tmp); } m_pLastEditedItem->replacePopup(m); - m_pLastEditedItem->setText(0,m->popupName()); + m_pLastEditedItem->setText(0, m->popupName()); } -void PopupEditorWidget::currentItemChanged(QTreeWidgetItem *it, QTreeWidgetItem *) +void PopupEditorWidget::currentItemChanged(QTreeWidgetItem * it, QTreeWidgetItem *) { saveLastEditedItem(); @@ -1296,7 +1365,7 @@ void PopupEditorWidget::currentItemChanged(QTreeWidgetItem *it, QTreeWidgetItem m_pEditor->edit(m_pLastEditedItem); } -void PopupEditorWidget::showEvent(QShowEvent *e) +void PopupEditorWidget::showEvent(QShowEvent * e) { oneTimeSetup(); QWidget::showEvent(e); @@ -1305,19 +1374,20 @@ void PopupEditorWidget::showEvent(QShowEvent *e) void PopupEditorWidget::commit() { m_bSaving = true; - if(!m_bOneTimeSetupDone)return; + if(!m_bOneTimeSetupDone) + return; saveLastEditedItem(); //KviKvsPopupManager::instance()->clear(); - int topcount=m_pTreeWidget->topLevelItemCount(); + int topcount = m_pTreeWidget->topLevelItemCount(); // Copy the original popup dict - KviPointerHashTable<QString,KviKvsPopupMenu> copy(*(KviKvsPopupManager::instance()->popupDict())); + KviPointerHashTable<QString, KviKvsPopupMenu> copy(*(KviKvsPopupManager::instance()->popupDict())); copy.setAutoDelete(false); - for(int i=0; i<topcount;i++) + for(int i = 0; i < topcount; i++) { MenuTreeWidgetItem * it = (MenuTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); KviKvsPopupMenu * p = KviKvsPopupManager::instance()->get(it->m_pPopup->popupName()); @@ -1329,7 +1399,7 @@ void PopupEditorWidget::commit() // the remaining elements in the copy need to be removed from // the "new" dictionary (they are no longer used) - KviPointerHashTableIterator<QString,KviKvsPopupMenu> iter(copy); + KviPointerHashTableIterator<QString, KviKvsPopupMenu> iter(copy); while(iter.current()) { @@ -1337,31 +1407,31 @@ void PopupEditorWidget::commit() ++iter; } - g_pApp->savePopups(); m_bSaving = false; } -void PopupEditorWidget::getUniquePopupName(MenuTreeWidgetItem *item,QString &buffer) +void PopupEditorWidget::getUniquePopupName(MenuTreeWidgetItem * item, QString & buffer) { KVI_ASSERT(m_bOneTimeSetupDone); - if(buffer.isEmpty())buffer = __tr2qs_ctx("unnamed","editor"); + if(buffer.isEmpty()) + buffer = __tr2qs_ctx("unnamed", "editor"); QString newName = buffer; bool bFound = true; int idx = 1; - int topcount=m_pTreeWidget->topLevelItemCount(); + int topcount = m_pTreeWidget->topLevelItemCount(); while(bFound) { bFound = false; - for(int i=0; i<topcount;i++) + for(int i = 0; i < topcount; i++) { MenuTreeWidgetItem * ch = (MenuTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); - if(KviQString::equalCI(newName,ch->m_pPopup->popupName()) && (ch != item)) + if(KviQString::equalCI(newName, ch->m_pPopup->popupName()) && (ch != item)) { bFound = true; newName = QString("%1.%2").arg(buffer).arg(idx); @@ -1369,39 +1439,37 @@ void PopupEditorWidget::getUniquePopupName(MenuTreeWidgetItem *item,QString &buf break; } } - } buffer = newName; } - PopupEditorWindow::PopupEditorWindow() -: KviWindow(KviWindow::ScriptEditor,"popupeditor",0) + : KviWindow(KviWindow::ScriptEditor, "popupeditor", 0) { g_pPopupEditorWindow = this; QGridLayout * g = new QGridLayout(); m_pEditor = new PopupEditorWidget(this); - g->addWidget(m_pEditor,0,0,1,4); + g->addWidget(m_pEditor, 0, 0, 1, 4); - QPushButton * btn = new QPushButton(__tr2qs_ctx("&OK","editor"),this); - connect(btn,SIGNAL(clicked()),this,SLOT(okClicked())); + QPushButton * btn = new QPushButton(__tr2qs_ctx("&OK", "editor"), this); + connect(btn, SIGNAL(clicked()), this, SLOT(okClicked())); btn->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Accept))); - g->addWidget(btn,1,1); + g->addWidget(btn, 1, 1); - btn = new QPushButton(__tr2qs_ctx("&Apply","editor"),this); - connect(btn,SIGNAL(clicked()),this,SLOT(applyClicked())); + btn = new QPushButton(__tr2qs_ctx("&Apply", "editor"), this); + connect(btn, SIGNAL(clicked()), this, SLOT(applyClicked())); btn->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Accept))); - g->addWidget(btn,1,2); + g->addWidget(btn, 1, 2); - btn = new QPushButton(__tr2qs_ctx("Cancel","editor"),this); - connect(btn,SIGNAL(clicked()),this,SLOT(cancelClicked())); + btn = new QPushButton(__tr2qs_ctx("Cancel", "editor"), this); + connect(btn, SIGNAL(clicked()), this, SLOT(cancelClicked())); btn->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Discard))); - g->addWidget(btn,1,3); + g->addWidget(btn, 1, 3); - g->setRowStretch(0,1); - g->setColumnStretch(0,1); + g->setRowStretch(0, 1); + g->setColumnStretch(0, 1); setLayout(g); } @@ -1433,17 +1501,17 @@ QPixmap * PopupEditorWindow::myIconPtr() void PopupEditorWindow::fillCaptionBuffers() { - m_szPlainTextCaption = __tr2qs_ctx("Popup Editor","editor"); + m_szPlainTextCaption = __tr2qs_ctx("Popup Editor", "editor"); } -void PopupEditorWindow::getConfigGroupName(QString &szName) +void PopupEditorWindow::getConfigGroupName(QString & szName) { szName = "popupeditor"; } void PopupEditorWindow::saveProperties(KviConfigurationFile *) //cfg { -/* + /* #ifdef COMPILE_SCRIPTTOOLBAR cfg->writeEntry("Sizes",m_pEditor->sizes()); cfg->writeEntry("LastPopup",m_pEditor->lastEditedPopup().ptr()); @@ -1454,7 +1522,7 @@ void PopupEditorWindow::saveProperties(KviConfigurationFile *) //cfg void PopupEditorWindow::loadProperties(KviConfigurationFile *) // cfg { -/* + /* #ifdef COMPILE_SCRIPTTOOLBAR QValueList<int> def; def.append(20); |
