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