forked from blue/squawk
VCard: email list now displays and stores on server vcard
This commit is contained in:
parent
0b57e6a77f
commit
5bbacad84a
9 changed files with 235 additions and 7 deletions
|
@ -15,18 +15,21 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "QTimer"
|
||||
|
||||
#include "comboboxdelegate.h"
|
||||
|
||||
ComboboxDelegate::ComboboxDelegate(QObject *parent):
|
||||
QStyledItemDelegate(parent),
|
||||
entries()
|
||||
entries(),
|
||||
ff(new FocusFilter())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ComboboxDelegate::~ComboboxDelegate()
|
||||
{
|
||||
delete ff;
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,6 +51,7 @@ void ComboboxDelegate::setEditorData(QWidget *editor, const QModelIndex &index)
|
|||
int currentIndex = index.data(Qt::EditRole).toInt();
|
||||
if (currentIndex >= 0) {
|
||||
cb->setCurrentIndex(currentIndex);
|
||||
cb->installEventFilter(ff);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,3 +66,20 @@ void ComboboxDelegate::addEntry(const QString& title, const QIcon& icon)
|
|||
{
|
||||
entries.emplace_back(title, icon);
|
||||
}
|
||||
|
||||
bool ComboboxDelegate::FocusFilter::eventFilter(QObject* src, QEvent* evt)
|
||||
{
|
||||
if (evt->type() == QEvent::FocusIn) {
|
||||
QComboBox* cb = static_cast<QComboBox*>(src);
|
||||
cb->removeEventFilter(this);
|
||||
QTimer* timer = new QTimer; //TODO that is ridiculous! I refuse to believe there is no better way than that one!
|
||||
QObject::connect(timer, &QTimer::timeout, [timer, cb]() {
|
||||
cb->showPopup();
|
||||
timer->deleteLater();
|
||||
});
|
||||
|
||||
timer->setSingleShot(true);
|
||||
timer->start(100);
|
||||
}
|
||||
return QObject::eventFilter(src, evt);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QComboBox>
|
||||
#include <QFocusEvent>
|
||||
|
||||
#include <deque>
|
||||
|
||||
|
@ -30,6 +31,12 @@
|
|||
class ComboboxDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class FocusFilter : public QObject {
|
||||
public:
|
||||
bool eventFilter(QObject *src, QEvent *evt) override;
|
||||
};
|
||||
|
||||
public:
|
||||
ComboboxDelegate(QObject *parent = nullptr);
|
||||
~ComboboxDelegate();
|
||||
|
@ -42,6 +49,9 @@ public:
|
|||
|
||||
private:
|
||||
std::deque<std::pair<QString, QIcon>> entries;
|
||||
FocusFilter* ff;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // COMBOBOXDELEGATE_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue