Changeset View
Standalone View
ui/formwidgets.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2007 by Pino Toscano <pino@kde.org> * | 2 | * Copyright (C) 2007 by Pino Toscano <pino@kde.org> * | ||
3 | * Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group * | 3 | * Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group * | ||
4 | * company, info@kdab.com. Work sponsored by the * | 4 | * company, info@kdab.com. Work sponsored by the * | ||
5 | * LiMux project of the city of Munich * | 5 | * LiMux project of the city of Munich * | ||
6 | * Copyright (C) 2018 Intevation GmbH <intevation@intevation.de> * | ||||
6 | * * | 7 | * * | ||
7 | * This program is free software; you can redistribute it and/or modify * | 8 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | 9 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | 10 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | 11 | * (at your option) any later version. * | ||
11 | ***************************************************************************/ | 12 | ***************************************************************************/ | ||
12 | 13 | | |||
13 | #include "formwidgets.h" | 14 | #include "formwidgets.h" | ||
▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Line(s) | |||||
367 | 368 | | |||
368 | 369 | | |||
369 | PushButtonEdit::PushButtonEdit( Okular::FormFieldButton * button, QWidget * parent ) | 370 | PushButtonEdit::PushButtonEdit( Okular::FormFieldButton * button, QWidget * parent ) | ||
370 | : QPushButton( parent ), FormWidgetIface( this, button ) | 371 | : QPushButton( parent ), FormWidgetIface( this, button ) | ||
371 | { | 372 | { | ||
372 | setText( button->caption() ); | 373 | setText( button->caption() ); | ||
373 | setVisible( button->isVisible() ); | 374 | setVisible( button->isVisible() ); | ||
374 | setCursor( Qt::ArrowCursor ); | 375 | setCursor( Qt::ArrowCursor ); | ||
375 | | ||||
376 | connect( this, &QAbstractButton::clicked, this, &PushButtonEdit::slotClicked ); | | |||
377 | } | | |||
378 | | ||||
379 | void PushButtonEdit::slotClicked() | | |||
380 | { | | |||
381 | if ( m_ff->activationAction() ) | | |||
382 | m_controller->signalAction( m_ff->activationAction() ); | | |||
383 | } | 376 | } | ||
384 | 377 | | |||
385 | 378 | | |||
386 | CheckBoxEdit::CheckBoxEdit( Okular::FormFieldButton * button, QWidget * parent ) | 379 | CheckBoxEdit::CheckBoxEdit( Okular::FormFieldButton * button, QWidget * parent ) | ||
387 | : QCheckBox( parent ), FormWidgetIface( this, button ) | 380 | : QCheckBox( parent ), FormWidgetIface( this, button ) | ||
388 | { | 381 | { | ||
389 | setText( button->caption() ); | 382 | setText( button->caption() ); | ||
390 | 383 | | |||
▲ Show 20 Lines • Show All 660 Lines • ▼ Show 20 Line(s) | 1036 | { | |||
1051 | { | 1044 | { | ||
1052 | emit m_controller->requestRedo(); | 1045 | emit m_controller->requestRedo(); | ||
1053 | return true; | 1046 | return true; | ||
1054 | } | 1047 | } | ||
1055 | } | 1048 | } | ||
1056 | return QComboBox::event( e ); | 1049 | return QComboBox::event( e ); | ||
1057 | } | 1050 | } | ||
1058 | 1051 | | |||
1052 | // Code for additional action handling. | ||||
1053 | // Challenge: Change preprocessor magic to C++ magic! | ||||
1054 | // | ||||
1055 | // The mouseRelease event is special because the PDF spec | ||||
1056 | // says that the activation action takes precedence over this. | ||||
1057 | // So the mouse release action is only signaled if no activation | ||||
1058 | // action exists. | ||||
1059 | // | ||||
1060 | // For checkboxes the activation action is not triggered as | ||||
1061 | // they are still triggered from the clicked signal and additionally | ||||
1062 | // when the checked state changes. | ||||
1063 | | ||||
1064 | #define DEFINE_ADDITIONAL_ACTIONS(FormClass, BaseClass) \ | ||||
1065 | void FormClass::mousePressEvent( QMouseEvent *event ) \ | ||||
1066 | { \ | ||||
1067 | Okular::Action *act = m_ff->additionalAction( Okular::Annotation::MousePressed ); \ | ||||
1068 | if ( act ) \ | ||||
1069 | { \ | ||||
1070 | m_controller->signalAction( act ); \ | ||||
1071 | } \ | ||||
1072 | BaseClass::mousePressEvent( event ); \ | ||||
1073 | } \ | ||||
aacid: This still triggers if you press the button inside a form, move the mouse outside the form and… | |||||
Right. I also tested with Acrobat and it only triggers if the mouse is released in the annotation area. aheinecke: > This still triggers if you press the button inside a form, move the mouse outside the form… | |||||
1074 | void FormClass::mouseReleaseEvent( QMouseEvent *event ) \ | ||||
1075 | { \ | ||||
1076 | if ( !QWidget::rect().contains( event->localPos().toPoint() ) ) \ | ||||
1077 | { \ | ||||
1078 | return; \ | ||||
Are you sure this should be an else? Why should activation action only be signaled if there's no mouse release action? Also, before we only did activation action for buttons, but now we do for lots of other forms, is that on purpose? aacid: Are you sure this should be an else? Why should activation action only be signaled if there's… | |||||
Good question. I checked in the spec and it should be the other way around. I was confused because Adobe Acrobat DC sets the "Mouse Released" action as the "A" entry of the annotation dictonary. This is parsed by poppler as the "Additional Action" Page 649 (Table 8.44) in the spec Says about the mouse released event: So it should be the other way around. Only execute the mouseReleased action if there is no activation action and execute the activation action otherwise. Checkboxes are handled differently because they trigger in the "doActivateAction" so that the action can also be triggered by scripts changing the checked state.
Yes this is on purpose. The activation action is not bound to buttons. I did not find it clearly stated in the spec but If I add a Mouse Release action on a textfield in Acrobat DC it is added as a Mouse Release action. And the Example from bug306818 uses a mouse action on a read only text field to hide the warning in there. aheinecke: > Are you sure this should be an else? Why should activation action only be signaled if there's… | |||||
Can you please add that explanation either as a comment somewhere in the code or as part of the git commit? It'll make it easier to find next time someone looks at the code and wonders why it has an "else " like i did. aacid: Can you please add that explanation either as a comment somewhere in the code or as part of the… | |||||
In the comment in line 1052ff I tried to do just that. A problem with the macros is that you cant properly do inline comments. aheinecke: In the comment in line 1052ff I tried to do just that. A problem with the macros is that you… | |||||
1079 | } \ | ||||
1080 | Okular::Action *act = m_ff->activationAction(); \ | ||||
1081 | if ( act && !qobject_cast< CheckBoxEdit* > ( this ) ) \ | ||||
1082 | { \ | ||||
1083 | m_controller->signalAction( act ); \ | ||||
1084 | } \ | ||||
1085 | else if ( ( act = m_ff->additionalAction( Okular::Annotation::MouseReleased ) ) ) \ | ||||
1086 | { \ | ||||
1087 | m_controller->signalAction( act ); \ | ||||
1088 | } \ | ||||
1089 | BaseClass::mouseReleaseEvent( event ); \ | ||||
1090 | } \ | ||||
1091 | void FormClass::focusInEvent( QFocusEvent *event ) \ | ||||
1092 | { \ | ||||
1093 | Okular::Action *act = m_ff->additionalAction( Okular::Annotation::FocusIn ); \ | ||||
1094 | if ( act ) \ | ||||
1095 | { \ | ||||
1096 | m_controller->signalAction( act ); \ | ||||
1097 | } \ | ||||
1098 | BaseClass::focusInEvent( event ); \ | ||||
1099 | } \ | ||||
1100 | void FormClass::focusOutEvent( QFocusEvent *event ) \ | ||||
1101 | { \ | ||||
1102 | Okular::Action *act = m_ff->additionalAction( Okular::Annotation::FocusOut ); \ | ||||
1103 | if ( act ) \ | ||||
1104 | { \ | ||||
1105 | m_controller->signalAction( act ); \ | ||||
1106 | } \ | ||||
1107 | BaseClass::focusOutEvent( event ); \ | ||||
1108 | } \ | ||||
1109 | void FormClass::leaveEvent( QEvent *event ) \ | ||||
1110 | { \ | ||||
1111 | Okular::Action *act = m_ff->additionalAction( Okular::Annotation::CursorLeaving ); \ | ||||
1112 | if ( act ) \ | ||||
1113 | { \ | ||||
1114 | m_controller->signalAction( act ); \ | ||||
1115 | } \ | ||||
1116 | BaseClass::leaveEvent( event ); \ | ||||
1117 | } \ | ||||
1118 | void FormClass::enterEvent( QEvent *event ) \ | ||||
1119 | { \ | ||||
1120 | Okular::Action *act = m_ff->additionalAction( Okular::Annotation::CursorEntering ); \ | ||||
1121 | if ( act ) \ | ||||
1122 | { \ | ||||
1123 | m_controller->signalAction( act ); \ | ||||
1124 | } \ | ||||
1125 | BaseClass::enterEvent( event ); \ | ||||
1126 | } | ||||
1127 | | ||||
1128 | DEFINE_ADDITIONAL_ACTIONS( PushButtonEdit, QPushButton ) | ||||
1129 | DEFINE_ADDITIONAL_ACTIONS( CheckBoxEdit, QCheckBox ) | ||||
1130 | DEFINE_ADDITIONAL_ACTIONS( RadioButtonEdit, QRadioButton ) | ||||
1131 | DEFINE_ADDITIONAL_ACTIONS( FormLineEdit, QLineEdit ) | ||||
1132 | DEFINE_ADDITIONAL_ACTIONS( TextAreaEdit, KTextEdit ) | ||||
1133 | DEFINE_ADDITIONAL_ACTIONS( FileEdit, KUrlRequester ) | ||||
1134 | DEFINE_ADDITIONAL_ACTIONS( ListEdit, QListWidget ) | ||||
1135 | DEFINE_ADDITIONAL_ACTIONS( ComboEdit, QComboBox ) | ||||
1136 | | ||||
1137 | #undef DEFINE_ADDITIONAL_ACTIONS | ||||
1138 | | ||||
1059 | #include "moc_formwidgets.cpp" | 1139 | #include "moc_formwidgets.cpp" |
This still triggers if you press the button inside a form, move the mouse outside the form and release, not sure this is "according to spec", it says "An action to be performed when the mouse button is released inside the annotation’s active area."