Changeset View
Changeset View
Standalone View
Standalone View
plugins/patchreview/patchreviewtoolview.cpp
Context not available. | |||||
40 | #include <QJsonObject> | 40 | #include <QJsonObject> | ||
---|---|---|---|---|---|
41 | #include <QJsonArray> | 41 | #include <QJsonArray> | ||
42 | 42 | | |||
43 | #include <QGestureEvent> | ||||
44 | #include <QGesture> | ||||
45 | #include <QTapAndHoldGesture> | ||||
46 | #include <QContextMenuEvent> | ||||
47 | | ||||
43 | #include <KMessageBox> | 48 | #include <KMessageBox> | ||
44 | #include <KLocalizedString> | 49 | #include <KLocalizedString> | ||
45 | #include <KTextEditor/Document> | 50 | #include <KTextEditor/Document> | ||
Context not available. | |||||
52 | 57 | | |||
53 | using namespace KDevelop; | 58 | using namespace KDevelop; | ||
54 | 59 | | |||
60 | class DiffContextMenu : public QObject | ||||
61 | { | ||||
62 | Q_OBJECT | ||||
63 | public: | ||||
64 | DiffContextMenu(PatchReviewPlugin *prPlugin) | ||||
65 | : QObject(dynamic_cast<QObject*>(prPlugin)) | ||||
66 | , m_prPlugin(prPlugin) | ||||
67 | { | ||||
68 | m_contextActions = new QActionGroup(this); | ||||
69 | m_contextActions->setExclusive(true); | ||||
70 | QAction *title = new QAction(i18n("diff context"), m_contextActions); | ||||
71 | title->setEnabled(false); | ||||
72 | m_contextActions->addAction(title); | ||||
73 | for (int i = 1; i <= 5; ++i) { | ||||
74 | addContextAction(i); | ||||
75 | } | ||||
76 | addContextAction(10); | ||||
77 | addContextAction(0); | ||||
78 | } | ||||
79 | | ||||
80 | void addContextAction(int contextLines) | ||||
81 | { | ||||
82 | QAction *action; | ||||
83 | if (contextLines == 0) { | ||||
84 | action = new QAction(i18n("whole file"), m_contextActions); | ||||
85 | } else if (contextLines > 0) { | ||||
86 | action = new QAction(i18n("%1 lines").arg(contextLines), m_contextActions); | ||||
87 | } else { | ||||
88 | return; | ||||
89 | } | ||||
90 | action->setData(contextLines); | ||||
91 | action->setCheckable(true); | ||||
92 | connect(action, &QAction::triggered, this, [action, this]() { | ||||
93 | action->setChecked(true); | ||||
94 | m_prPlugin->forceUpdateWithContext(action->data().toInt()); | ||||
95 | }); | ||||
96 | m_contextActions->addAction(action); | ||||
97 | if (contextLines == 3) { | ||||
98 | m_defaultContextAction = action; | ||||
99 | action->setChecked(true); | ||||
100 | } | ||||
101 | } | ||||
102 | | ||||
103 | bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE | ||||
104 | { | ||||
105 | if (event->type() == QEvent::Gesture) { | ||||
106 | QGestureEvent *gEvent = static_cast<QGestureEvent*>(event); | ||||
107 | if (QTapAndHoldGesture *heldTap = static_cast<QTapAndHoldGesture*>(gEvent->gesture(Qt::TapAndHoldGesture))) { | ||||
108 | if (heldTap->state() == Qt::GestureFinished) { | ||||
109 | QPushButton *btn = dynamic_cast<QPushButton*>(obj); | ||||
110 | if (btn) { | ||||
111 | // user clicked and held a widget, send it a simulated ContextMenuEvent: | ||||
112 | QContextMenuEvent ce(QContextMenuEvent::Mouse, heldTap->position().toPoint(), | ||||
113 | heldTap->hotSpot().toPoint()); | ||||
114 | gEvent->accept(); | ||||
115 | int ret = QCoreApplication::sendEvent(btn, &ce); | ||||
116 | btn->setDown(false); | ||||
117 | return ret; | ||||
118 | } | ||||
119 | } | ||||
120 | } | ||||
121 | } | ||||
122 | return false; | ||||
123 | } | ||||
124 | | ||||
125 | QActionGroup *m_contextActions; | ||||
126 | PatchReviewPlugin *m_prPlugin; | ||||
127 | QAction *m_defaultContextAction; | ||||
128 | }; | ||||
129 | | ||||
55 | class PatchFilesModel : public VcsFileChangesModel | 130 | class PatchFilesModel : public VcsFileChangesModel | ||
56 | { | 131 | { | ||
57 | Q_OBJECT | 132 | Q_OBJECT | ||
Context not available. | |||||
129 | } | 204 | } | ||
130 | 205 | | |||
131 | void PatchReviewToolView::patchChanged() { | 206 | void PatchReviewToolView::patchChanged() { | ||
207 | if(m_resetCheckedUrls) { | ||||
208 | // set the default number of context lines | ||||
209 | m_editPatch.diffContext->setValue(3); | ||||
210 | m_diffContextMenu->m_defaultContextAction->setChecked(true); | ||||
211 | } | ||||
212 | | ||||
132 | fillEditFromPatch(); | 213 | fillEditFromPatch(); | ||
133 | kompareModelChanged(); | 214 | kompareModelChanged(); | ||
134 | 215 | | |||
Context not available. | |||||
252 | //connect( this, SIGNAL(finished(int)), this, SLOT(slotEditDialogFinished(int)) ); | 333 | //connect( this, SIGNAL(finished(int)), this, SLOT(slotEditDialogFinished(int)) ); | ||
253 | 334 | | |||
254 | connect( m_editPatch.updateButton, &QPushButton::clicked, m_plugin, &PatchReviewPlugin::forceUpdate ); | 335 | connect( m_editPatch.updateButton, &QPushButton::clicked, m_plugin, &PatchReviewPlugin::forceUpdate ); | ||
336 | m_editPatch.updateButton->setContextMenuPolicy(Qt::ActionsContextMenu); | ||||
337 | m_diffContextMenu = new DiffContextMenu(m_plugin); | ||||
338 | m_editPatch.updateButton->addActions(m_diffContextMenu->m_contextActions->actions()); | ||||
339 | // make it possible to open the context menu with a click-and-hold: | ||||
340 | m_editPatch.updateButton->installEventFilter(m_diffContextMenu); | ||||
341 | m_editPatch.updateButton->grabGesture(Qt::TapAndHoldGesture); | ||||
342 | // FIXME: cleanup after deciding on the GUI | ||||
343 | m_editPatch.diffContext->hide(); | ||||
344 | // connect( m_editPatch.diffContext, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), | ||||
345 | // m_plugin, &PatchReviewPlugin::forceUpdateWithContext ); | ||||
255 | 346 | | |||
256 | connect( m_editPatch.testsButton, &QPushButton::clicked, this, &PatchReviewToolView::runTests ); | 347 | connect( m_editPatch.testsButton, &QPushButton::clicked, this, &PatchReviewToolView::runTests ); | ||
257 | 348 | | |||
Context not available. |