Qt: Fixed issue #9935. ComboBox can add new items now, when editable of course.

git-svn-id: trunk@12458 -
This commit is contained in:
zeljko 2007-10-14 10:10:04 +00:00
parent 3473b94d76
commit e37222cbea

View File

@ -594,7 +594,6 @@ type
FOwnerDrawn: Boolean; FOwnerDrawn: Boolean;
FSelectHook: QComboBox_hookH; FSelectHook: QComboBox_hookH;
FDropListEventHook: QObject_hookH; FDropListEventHook: QObject_hookH;
FLineEditEventHook: QObject_hookH;
// parts // parts
FLineEdit: QLineEditH; FLineEdit: QLineEditH;
FDropList: TQtListWidget; FDropList: TQtListWidget;
@ -4786,9 +4785,7 @@ begin
if FLineEdit = nil then if FLineEdit = nil then
begin begin
FLineEdit := QComboBox_lineEdit(QComboBoxH(Widget)); FLineEdit := QComboBox_lineEdit(QComboBoxH(Widget));
FLineEditEventHook := QWidget_hook_create(FLineEdit); QObject_disconnect(FLineEdit,'2returnPressed()', Widget, '1_q_returnPressed()');
TEventFilterMethod(Method) := @EventFilter;
QObject_hook_hook_events(FLineEditEventHook, Method);
end; end;
end; end;
Result := FLineEdit; Result := FLineEdit;
@ -5010,6 +5007,7 @@ end;
function TQtComboBox.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; function TQtComboBox.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
var var
ev: QEventH; ev: QEventH;
str: WideString;
begin begin
BeginEventProcessing; BeginEventProcessing;
if (FDropList <> nil) and (Sender = FDropList.Widget) then if (FDropList <> nil) and (Sender = FDropList.Widget) then
@ -5032,18 +5030,6 @@ begin
QEvent_ignore(Event); QEvent_ignore(Event);
end; end;
end else end else
if (Sender = FLineEdit) then
begin
Result := False;
case QEvent_type(Event) of
QEventKeyPress,
QEventKeyRelease:
begin
QEvent_accept(Event);
Result := SlotKey(Sender, Event);
end;
end;
end else
begin begin
case QEvent_type(Event) of case QEvent_type(Event) of
QEventFocusIn: QEventFocusIn:
@ -5057,6 +5043,27 @@ begin
QLineEdit_selectAll(QLineEditH(LineEdit)); QLineEdit_selectAll(QLineEditH(LineEdit));
end; end;
end; end;
QEventKeyPress,
QEventKeyRelease:
begin
if (QEvent_type(Event) = QEventKeyRelease) and
((QKeyEvent_key(QKeyEventH(Event)) = QtKey_Return) or
(QKeyEvent_key(QKeyEventH(Event)) = QtKey_Enter)) and
(QKeyEvent_modifiers(QKeyEventH(Event)) = QtNoModifier) and
(FLineEdit <> nil) and (QWidget_hasFocus(FLineEdit)) then
begin
Str := UTF8Encode(getText);
if TCustomComboBox(LCLObject).Items.IndexOf(Str) < 0 then
TCustomComboBox(LCLObject).AddItem(Str, nil);
end;
QEvent_accept(Event);
Result := SlotKey(Sender, Event);
end;
end; end;
Result := inherited EventFilter(Sender, Event); Result := inherited EventFilter(Sender, Event);
end; end;