1 /*************************************************************************** 2 * Copyright (C) 2004-2021 by Pere Constans 3 * constans@molspaces.com 4 * cb2Bib version 2.0.1. Licensed under the GNU GPL version 3. 5 * See the LICENSE file that comes with this distribution. 6 ***************************************************************************/ 7 #include "c2bComboBox.h" 8 9 #include <QAction> 10 #include <QContextMenuEvent> 11 #include <QLineEdit> 12 #include <QMenu> 13 14 15 c2bComboBox::c2bComboBox(QWidget* parentw) : QComboBox(parentw) {} 16 17 c2bComboBox::~c2bComboBox() {} 18 19 20 void c2bComboBox::contextMenuEvent(QContextMenuEvent* e) 21 { 22 QMenu* menu = QComboBox::lineEdit()->createStandardContextMenu(); 23 QList<QAction*> acts = menu->actions(); 24 QAction* act; 25 act = new QAction("Clear", menu); 26 act->setEnabled(!QComboBox::lineEdit()->text().isEmpty()); 27 connect(act, SIGNAL(triggered()), this, SLOT(clearEditText())); 28 menu->insertAction(acts.at(7), act); 29 acts = actions(); 30 for (int i = 0; i < acts.count(); ++i) 31 menu->addAction(acts.at(i)); 32 menu->exec(e->globalPos()); 33 delete menu; 34 }