Changeset View
Changeset View
Standalone 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 | * Copyright (C) 2018 Intevation GmbH <intevation@intevation.de> * | ||
7 | * * | 7 | * * | ||
8 | * 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 * | ||
9 | * 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 * | ||
10 | * the Free Software Foundation; either version 2 of the License, or * | 10 | * the Free Software Foundation; either version 2 of the License, or * | ||
11 | * (at your option) any later version. * | 11 | * (at your option) any later version. * | ||
12 | ***************************************************************************/ | 12 | ***************************************************************************/ | ||
13 | 13 | | |||
14 | #include "formwidgets.h" | 14 | #include "formwidgets.h" | ||
15 | #include "pageviewutils.h" | 15 | #include "pageviewutils.h" | ||
16 | #include "signaturewidgets.h" | ||||
16 | 17 | | |||
17 | #include <qbuttongroup.h> | 18 | #include <qbuttongroup.h> | ||
18 | #include <QKeyEvent> | 19 | #include <QKeyEvent> | ||
19 | #include <QMenu> | 20 | #include <QMenu> | ||
20 | #include <QEvent> | 21 | #include <QEvent> | ||
21 | #include <klineedit.h> | 22 | #include <klineedit.h> | ||
22 | #include <KLocalizedString> | 23 | #include <KLocalizedString> | ||
23 | #include <kstandardaction.h> | 24 | #include <kstandardaction.h> | ||
24 | #include <qaction.h> | 25 | #include <qaction.h> | ||
25 | #include <QUrl> | 26 | #include <QUrl> | ||
27 | #include <QPainter> | ||||
26 | 28 | | |||
27 | // local includes | 29 | // local includes | ||
28 | #include "core/form.h" | 30 | #include "core/form.h" | ||
29 | #include "core/document.h" | 31 | #include "core/document.h" | ||
30 | #include "debug_ui.h" | 32 | #include "debug_ui.h" | ||
31 | 33 | | |||
32 | FormWidgetsController::FormWidgetsController( Okular::Document *doc ) | 34 | FormWidgetsController::FormWidgetsController( Okular::Document *doc ) | ||
33 | : QObject( doc ), m_doc( doc ) | 35 | : QObject( doc ), m_doc( doc ) | ||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Line(s) | 272 | case Okular::FormFieldChoice::ListBox: | |||
271 | widget = new ListEdit( ffc, parent ); | 273 | widget = new ListEdit( ffc, parent ); | ||
272 | break; | 274 | break; | ||
273 | case Okular::FormFieldChoice::ComboBox: | 275 | case Okular::FormFieldChoice::ComboBox: | ||
274 | widget = new ComboEdit( ffc, parent ); | 276 | widget = new ComboEdit( ffc, parent ); | ||
275 | break; | 277 | break; | ||
276 | } | 278 | } | ||
277 | break; | 279 | break; | ||
278 | } | 280 | } | ||
281 | case Okular::FormField::FormSignature: | ||||
282 | { | ||||
283 | Okular::FormFieldSignature * ffs = static_cast< Okular::FormFieldSignature * >( ff ); | ||||
284 | if ( ffs->isVisible() && ffs->signatureType() != Okular::FormFieldSignature::UnknownType ) | ||||
285 | widget = new SignatureEdit( ffs, parent ); | ||||
286 | break; | ||||
287 | } | ||||
279 | default: ; | 288 | default: ; | ||
280 | } | 289 | } | ||
281 | 290 | | |||
282 | if ( ff->isReadOnly() ) | 291 | if ( ff->isReadOnly() ) | ||
283 | widget->setVisibility( false ); | 292 | widget->setVisibility( false ); | ||
284 | 293 | | |||
285 | return widget; | 294 | return widget; | ||
286 | } | 295 | } | ||
▲ Show 20 Lines • Show All 757 Lines • ▼ Show 20 Line(s) | 1045 | { | |||
1044 | { | 1053 | { | ||
1045 | emit m_controller->requestRedo(); | 1054 | emit m_controller->requestRedo(); | ||
1046 | return true; | 1055 | return true; | ||
1047 | } | 1056 | } | ||
1048 | } | 1057 | } | ||
1049 | return QComboBox::event( e ); | 1058 | return QComboBox::event( e ); | ||
1050 | } | 1059 | } | ||
1051 | 1060 | | |||
1061 | SignatureEdit::SignatureEdit( Okular::FormFieldSignature * signature, QWidget * parent ) | ||||
1062 | : QAbstractButton( parent ), FormWidgetIface( this, signature ), | ||||
1063 | m_sigInfo( nullptr ), m_lefMouseButtonPressed( false ) | ||||
1064 | { | ||||
1065 | setCheckable( false ); | ||||
1066 | setCursor( Qt::PointingHandCursor ); | ||||
1067 | connect( this, &SignatureEdit::clicked, this, &SignatureEdit::slotShowSummary ); | ||||
1068 | } | ||||
1069 | | ||||
1070 | bool SignatureEdit::event( QEvent * e ) | ||||
1071 | { | ||||
1072 | switch ( e->type() ) | ||||
1073 | { | ||||
1074 | case QEvent::MouseButtonPress: | ||||
1075 | { | ||||
1076 | QMouseEvent *ev = static_cast< QMouseEvent * >( e ); | ||||
1077 | if ( ev->button() == Qt::LeftButton ) | ||||
1078 | { | ||||
1079 | m_lefMouseButtonPressed = true; | ||||
1080 | update(); | ||||
1081 | } | ||||
1082 | mousePressEvent( ev ); | ||||
1083 | break; | ||||
1084 | } | ||||
1085 | case QEvent::MouseButtonRelease: | ||||
1086 | { | ||||
1087 | QMouseEvent *ev = static_cast< QMouseEvent * >( e ); | ||||
1088 | m_lefMouseButtonPressed = false; | ||||
1089 | if ( ev->button() == Qt::LeftButton) | ||||
1090 | { | ||||
1091 | update(); | ||||
1092 | } | ||||
1093 | mouseReleaseEvent( ev ); | ||||
1094 | break; | ||||
1095 | } | ||||
1096 | default: | ||||
1097 | break; | ||||
1098 | } | ||||
1099 | | ||||
1100 | return QAbstractButton::event( e ); | ||||
1101 | } | ||||
1102 | | ||||
1103 | void SignatureEdit::contextMenuEvent( QContextMenuEvent * event ) | ||||
1104 | { | ||||
1105 | QMenu *menu = new QMenu( this ); | ||||
1106 | QAction *sigVal = new QAction( i18n("Validate Signature"), this ); | ||||
1107 | menu->addAction( sigVal ); | ||||
1108 | connect( sigVal, &QAction::triggered, this, &SignatureEdit::slotShowSummary ); | ||||
1109 | QAction *sigProp = new QAction( i18n("Show Signature Properties"), this ); | ||||
1110 | sigProp->setEnabled( m_sigInfo != nullptr ); | ||||
1111 | menu->addAction( sigProp ); | ||||
1112 | connect( sigProp, &QAction::triggered, this, &SignatureEdit::slotShowProperties ); | ||||
1113 | menu->exec( event->globalPos() ); | ||||
1114 | delete menu; | ||||
1115 | } | ||||
1116 | | ||||
1117 | void SignatureEdit::paintEvent( QPaintEvent * ) | ||||
1118 | { | ||||
1119 | QPainter painter( this ); | ||||
aacid: What's the reason for this custom paint code? | |||||
1120 | painter.setPen( Qt::black ); | ||||
1121 | if ( m_lefMouseButtonPressed ) | ||||
1122 | { | ||||
1123 | QColor col = palette().color( QPalette::Active, QPalette::Highlight ); | ||||
1124 | col.setAlpha(50); | ||||
1125 | painter.setBrush( col ); | ||||
1126 | } | ||||
1127 | else | ||||
1128 | { | ||||
1129 | painter.setBrush( Qt::transparent ); | ||||
1130 | } | ||||
1131 | painter.drawRect( 0, 0, width()-2, height()-2 ); | ||||
1132 | } | ||||
1133 | | ||||
1134 | Okular::SignatureInfo *SignatureEdit::validate() | ||||
1135 | { | ||||
1136 | Okular::FormFieldSignature *sigField = static_cast< Okular::FormFieldSignature * >( formField() ); | ||||
1137 | m_sigInfo = sigField->validate(); | ||||
1138 | return m_sigInfo; | ||||
1139 | } | ||||
1140 | | ||||
1141 | void SignatureEdit::slotShowSummary() | ||||
1142 | { | ||||
1143 | validate(); | ||||
1144 | if ( !m_sigInfo ) | ||||
1145 | return; | ||||
1146 | | ||||
1147 | SignatureSummaryDialog sigSummaryDlg( m_sigInfo, this ); | ||||
1148 | sigSummaryDlg.exec(); | ||||
1149 | } | ||||
1150 | | ||||
1151 | void SignatureEdit::slotShowProperties() | ||||
1152 | { | ||||
1153 | if ( !m_sigInfo ) | ||||
1154 | return; | ||||
1155 | | ||||
1156 | SignaturePropertiesDialog sigPropDlg( m_sigInfo, this ); | ||||
1157 | sigPropDlg.exec(); | ||||
1158 | } | ||||
1159 | | ||||
1052 | // Code for additional action handling. | 1160 | // Code for additional action handling. | ||
1053 | // Challenge: Change preprocessor magic to C++ magic! | 1161 | // Challenge: Change preprocessor magic to C++ magic! | ||
1054 | // | 1162 | // | ||
1055 | // The mouseRelease event is special because the PDF spec | 1163 | // The mouseRelease event is special because the PDF spec | ||
1056 | // says that the activation action takes precedence over this. | 1164 | // says that the activation action takes precedence over this. | ||
1057 | // So the mouse release action is only signaled if no activation | 1165 | // So the mouse release action is only signaled if no activation | ||
1058 | // action exists. | 1166 | // action exists. | ||
1059 | // | 1167 | // | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
1129 | DEFINE_ADDITIONAL_ACTIONS( PushButtonEdit, QPushButton ) | 1237 | DEFINE_ADDITIONAL_ACTIONS( PushButtonEdit, QPushButton ) | ||
1130 | DEFINE_ADDITIONAL_ACTIONS( CheckBoxEdit, QCheckBox ) | 1238 | DEFINE_ADDITIONAL_ACTIONS( CheckBoxEdit, QCheckBox ) | ||
1131 | DEFINE_ADDITIONAL_ACTIONS( RadioButtonEdit, QRadioButton ) | 1239 | DEFINE_ADDITIONAL_ACTIONS( RadioButtonEdit, QRadioButton ) | ||
1132 | DEFINE_ADDITIONAL_ACTIONS( FormLineEdit, QLineEdit ) | 1240 | DEFINE_ADDITIONAL_ACTIONS( FormLineEdit, QLineEdit ) | ||
1133 | DEFINE_ADDITIONAL_ACTIONS( TextAreaEdit, KTextEdit ) | 1241 | DEFINE_ADDITIONAL_ACTIONS( TextAreaEdit, KTextEdit ) | ||
1134 | DEFINE_ADDITIONAL_ACTIONS( FileEdit, KUrlRequester ) | 1242 | DEFINE_ADDITIONAL_ACTIONS( FileEdit, KUrlRequester ) | ||
1135 | DEFINE_ADDITIONAL_ACTIONS( ListEdit, QListWidget ) | 1243 | DEFINE_ADDITIONAL_ACTIONS( ListEdit, QListWidget ) | ||
1136 | DEFINE_ADDITIONAL_ACTIONS( ComboEdit, QComboBox ) | 1244 | DEFINE_ADDITIONAL_ACTIONS( ComboEdit, QComboBox ) | ||
1245 | DEFINE_ADDITIONAL_ACTIONS( SignatureEdit, QAbstractButton ) | ||||
1137 | 1246 | | |||
1138 | #undef DEFINE_ADDITIONAL_ACTIONS | 1247 | #undef DEFINE_ADDITIONAL_ACTIONS | ||
1139 | 1248 | | |||
1140 | #include "moc_formwidgets.cpp" | 1249 | #include "moc_formwidgets.cpp" |
What's the reason for this custom paint code?