subsurface/qt-ui/modeldelegates.h
Tomaz Canabrava e6be14bf10 Make the Qt ComboBox behave in a Better Way
So, the ComboBox is a beast, and when used on a Delegate
it's very hard to get things right, wich is a pitty, because
I overly like qt. So:

1 - Combobox needs to show the popup when user press ↓ and ↑ keys
2 - Combobox needs to select when user press enter, not twice.
3 - Combobox neesds to select when user selects from the mouse, not
pressing enter after.
4 - Combobox needs to not mess with stuff when moving around.

Everything that I listed there works on a non-delegate combobox,
but for some reason, a delegate missed those, so I reimplemented
all. not nice, but now we have a code that will work, I hope.
*fingers crossed*

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-09-25 12:48:24 -07:00

63 lines
2.4 KiB
C++

#ifndef MODELDELEGATES_H
#define MODELDELEGATES_H
#include <QStyledItemDelegate>
class QComboBox;
class StarWidgetsDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit StarWidgetsDelegate(QWidget* parent = 0);
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
QWidget *parentWidget;
};
class ComboBoxDelegate : public QStyledItemDelegate{
Q_OBJECT
public:
explicit ComboBoxDelegate(QAbstractItemModel *model, QObject* parent = 0);
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const;
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual bool eventFilter(QObject* object, QEvent* event);
public slots:
void testActivation(const QString& s);
//HACK: try to get rid of this in the future.
void fakeActivation();
virtual void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint) = 0;
protected:
QAbstractItemModel *model;
};
class TankInfoDelegate : public ComboBoxDelegate{
Q_OBJECT
public:
explicit TankInfoDelegate(QObject* parent = 0);
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
public slots:
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
};
class WSInfoDelegate : public ComboBoxDelegate{
Q_OBJECT
public:
explicit WSInfoDelegate(QObject* parent = 0);
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
public slots:
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
};
class AirTypesDelegate : public ComboBoxDelegate{
Q_OBJECT
public:
explicit AirTypesDelegate(QObject* parent = 0);
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
public slots:
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
};
#endif