Changeset View
Standalone View
src/dialogs/katedialogs.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
65 | #include <KLineEdit> | 65 | #include <KLineEdit> | ||
66 | #include <KMessageBox> | 66 | #include <KMessageBox> | ||
67 | #include <KProcess> | 67 | #include <KProcess> | ||
68 | #include <KRun> | 68 | #include <KRun> | ||
69 | #include <KSeparator> | 69 | #include <KSeparator> | ||
70 | #include <KActionCollection> | 70 | #include <KActionCollection> | ||
71 | 71 | | |||
72 | #include <QFile> | 72 | #include <QFile> | ||
73 | #include <QClipboard> | ||||
73 | #include <QMap> | 74 | #include <QMap> | ||
74 | #include <QStringList> | 75 | #include <QStringList> | ||
75 | #include <QTextCodec> | 76 | #include <QTextCodec> | ||
76 | #include <QTextStream> | 77 | #include <QTextStream> | ||
77 | #include <QTemporaryFile> | 78 | #include <QTemporaryFile> | ||
78 | #include <QKeyEvent> | 79 | #include <QKeyEvent> | ||
79 | #include <QPainter> | 80 | #include <QPainter> | ||
80 | #include <QCheckBox> | 81 | #include <QCheckBox> | ||
▲ Show 20 Lines • Show All 981 Lines • ▼ Show 20 Line(s) | |||||
1062 | KateGotoBar::KateGotoBar(KTextEditor::View *view, QWidget *parent) | 1063 | KateGotoBar::KateGotoBar(KTextEditor::View *view, QWidget *parent) | ||
1063 | : KateViewBarWidget(true, parent) | 1064 | : KateViewBarWidget(true, parent) | ||
1064 | , m_view(view) | 1065 | , m_view(view) | ||
1065 | { | 1066 | { | ||
1066 | Q_ASSERT(m_view != nullptr); // this bar widget is pointless w/o a view | 1067 | Q_ASSERT(m_view != nullptr); // this bar widget is pointless w/o a view | ||
1067 | 1068 | | |||
1068 | QHBoxLayout *topLayout = new QHBoxLayout(centralWidget()); | 1069 | QHBoxLayout *topLayout = new QHBoxLayout(centralWidget()); | ||
1069 | topLayout->setMargin(0); | 1070 | topLayout->setMargin(0); | ||
1070 | gotoRange = new QSpinBox(centralWidget()); | | |||
1071 | 1071 | | |||
1072 | QLabel *label = new QLabel(i18n("&Go to line:"), centralWidget()); | 1072 | QToolButton *btn = new QToolButton(this); | ||
1073 | label->setBuddy(gotoRange); | 1073 | btn->setAutoRaise(true); | ||
1074 | btn->setMinimumSize(QSize(1, btn->minimumSizeHint().height())); | ||||
1075 | btn->setText(i18n("&Line:")); | ||||
1076 | btn->setToolTip(i18n("Go to line number from clipboard")); | ||||
1077 | connect(btn, &QToolButton::clicked, this, &KateGotoBar::gotoClipboard); | ||||
1078 | topLayout->addWidget(btn); | ||||
1079 | | ||||
1080 | m_gotoRange = new QSpinBox(this); | ||||
1081 | m_gotoRange->setMinimum(1); | ||||
1082 | topLayout->addWidget(m_gotoRange, 1); | ||||
1083 | topLayout->setStretchFactor(m_gotoRange, 0); | ||||
1084 | | ||||
1085 | btn = new QToolButton(this); | ||||
1086 | btn->setAutoRaise(true); | ||||
1087 | btn->setMinimumSize(QSize(1, btn->minimumSizeHint().height())); | ||||
1088 | btn->setText(i18n("Go to")); | ||||
1089 | btn->setIcon(QIcon::fromTheme(QStringLiteral("go-jump"))); | ||||
1090 | btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||||
1091 | connect(btn, &QToolButton::clicked, this, &KateGotoBar::gotoLine); | ||||
1092 | topLayout->addWidget(btn); | ||||
1093 | | ||||
1094 | btn = m_modifiedUp = new QToolButton(this); | ||||
1095 | btn->setAutoRaise(true); | ||||
1096 | btn->setMinimumSize(QSize(1, btn->minimumSizeHint().height())); | ||||
1097 | btn->setDefaultAction(m_view->action("modified_line_up")); | ||||
1098 | btn->setIcon(QIcon::fromTheme(QStringLiteral("go-up-search"))); | ||||
1099 | btn->setText(QString()); | ||||
dhaumann: Please always use QString() in favor of QStringLiteral("") | |||||
1100 | btn->installEventFilter(this); | ||||
1101 | topLayout->addWidget(btn); | ||||
1102 | | ||||
1103 | btn = m_modifiedDown = new QToolButton(this); | ||||
1104 | btn->setAutoRaise(true); | ||||
1105 | btn->setMinimumSize(QSize(1, btn->minimumSizeHint().height())); | ||||
1106 | btn->setDefaultAction(m_view->action("modified_line_down")); | ||||
1107 | btn->setIcon(QIcon::fromTheme(QStringLiteral("go-down-search"))); | ||||
1108 | btn->setText(QString()); | ||||
1109 | btn->installEventFilter(this); | ||||
1110 | topLayout->addWidget(btn); | ||||
1074 | 1111 | | |||
1075 | QToolButton *btnOK = new QToolButton(centralWidget()); | | |||
1076 | btnOK->setAutoRaise(true); | | |||
1077 | btnOK->setIcon(QIcon::fromTheme(QStringLiteral("go-jump"))); | | |||
1078 | btnOK->setText(i18n("Go")); | | |||
1079 | btnOK->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | | |||
1080 | connect(btnOK, SIGNAL(clicked()), this, SLOT(gotoLine())); | | |||
1081 | | ||||
1082 | topLayout->addWidget(label); | | |||
1083 | topLayout->addWidget(gotoRange, 1); | | |||
1084 | topLayout->setStretchFactor(gotoRange, 0); | | |||
1085 | topLayout->addWidget(btnOK); | | |||
1086 | topLayout->addStretch(); | 1112 | topLayout->addStretch(); | ||
1087 | 1113 | | |||
1088 | setFocusProxy(gotoRange); | 1114 | setFocusProxy(m_gotoRange); | ||
1115 | } | ||||
1116 | | ||||
1117 | void KateGotoBar::showEvent(QShowEvent *event) | ||||
1118 | { | ||||
1119 | Q_UNUSED(event) | ||||
1120 | // Catch rare cases where the bar is visible while document is edited | ||||
1121 | connect(m_view->document(), &KTextEditor::Document::textChanged, this, &KateGotoBar::updateData); | ||||
1122 | } | ||||
1123 | | ||||
1124 | void KateGotoBar::closed() | ||||
1125 | { | ||||
1126 | disconnect(m_view->document(), &KTextEditor::Document::textChanged, this, &KateGotoBar::updateData); | ||||
1127 | } | ||||
1128 | | ||||
1129 | bool KateGotoBar::eventFilter(QObject *object, QEvent *event) | ||||
1130 | { | ||||
https://doc.qt.io/qt-5/qwheelevent.html#angleDelta anthonyfieroni: https://doc.qt.io/qt-5/qwheelevent.html#angleDelta
It should be 120, also you can have 2… | |||||
Why? Have now read the doc, but without a new insight.
How and why? loh.tar: > It should be 120,
Why? Have now read the doc, but without a new insight.
> also you can have… | |||||
I don't know what is unclear, it should be 120 not any other value. if (object == m_ModifiedUp) { m_deltaUp += event->delta(); if (m_deltaUp >= 120) { m_ModifiedUp->click(); } and so on. If not do it right you can end up in partial value when it used finer-resolution wheels and mishmash. anthonyfieroni: > you can either cumulatively add the delta values from events until the value of 120 is… | |||||
I think 120 would be better to use, as that is the value one should start to handle given the docs. cullmann: I think 120 would be better to use, as that is the value one should start to handle given the… | |||||
1131 | if (object == m_modifiedUp || object == m_modifiedDown) { | ||||
1132 | if (event->type() != QEvent::Wheel) { | ||||
1133 | return false; | ||||
1134 | } | ||||
1135 | | ||||
1136 | int delta = static_cast<QWheelEvent *>(event)->delta(); | ||||
1137 | // Reset m_wheelDelta when scroll direction change | ||||
1138 | if (m_wheelDelta != 0 && (m_wheelDelta < 0) != (delta < 0)) { | ||||
1139 | m_wheelDelta = 0; | ||||
1140 | } | ||||
1141 | | ||||
1142 | m_wheelDelta += delta; | ||||
1143 | | ||||
1144 | if (m_wheelDelta >= 120) { | ||||
1145 | m_wheelDelta = 0; | ||||
1146 | m_modifiedUp->click(); | ||||
1147 | } else if (m_wheelDelta <= -120) { | ||||
1148 | m_wheelDelta = 0; | ||||
1149 | m_modifiedDown->click(); | ||||
1150 | } | ||||
1151 | } | ||||
1152 | | ||||
1153 | return false; | ||||
1154 | } | ||||
1155 | | ||||
1156 | void KateGotoBar::gotoClipboard() | ||||
You should also call message->setView(m_view), otherwise the message appears in all views, in case you have multiple views of a document. dhaumann: You should also call message->setView(m_view), otherwise the message appears in all views, in… | |||||
1157 | { | ||||
1158 | QRegularExpression rx(QStringLiteral("\\d+")); | ||||
1159 | int lineNo = rx.match(QApplication::clipboard()->text(QClipboard::Selection)).captured().toInt(); | ||||
1160 | if (lineNo <= m_gotoRange->maximum() && lineNo >= 1) { | ||||
1161 | m_gotoRange->setValue(lineNo); | ||||
1162 | gotoLine(); | ||||
1163 | } else { | ||||
1164 | QPointer<KTextEditor::Message> message = new KTextEditor::Message( | ||||
1165 | i18n("No valid line number found in clipboard")); | ||||
1166 | message->setWordWrap(true); | ||||
1167 | message->setAutoHide(2000); | ||||
1168 | message->setPosition(KTextEditor::Message::BottomInView); | ||||
1169 | message->setView(m_view), | ||||
1170 | m_view->document()->postMessage(message); | ||||
1171 | } | ||||
1089 | } | 1172 | } | ||
1090 | 1173 | | |||
1091 | void KateGotoBar::updateData() | 1174 | void KateGotoBar::updateData() | ||
1092 | { | 1175 | { | ||
1093 | gotoRange->setMaximum(m_view->document()->lines()); | 1176 | m_gotoRange->setMaximum(m_view->document()->lines()); | ||
1094 | if (!isVisible()) { | 1177 | if (!isVisible()) { | ||
1095 | gotoRange->setValue(m_view->cursorPosition().line() + 1); | 1178 | m_gotoRange->setValue(m_view->cursorPosition().line() + 1); | ||
1096 | gotoRange->adjustSize(); // ### does not respect the range :-( | 1179 | m_gotoRange->adjustSize(); // ### does not respect the range :-( | ||
1097 | } | 1180 | } | ||
1098 | gotoRange->setFocus(Qt::OtherFocusReason); | 1181 | | ||
1099 | gotoRange->selectAll(); | 1182 | m_gotoRange->selectAll(); | ||
1100 | } | 1183 | } | ||
1101 | 1184 | | |||
1102 | void KateGotoBar::keyPressEvent(QKeyEvent *event) | 1185 | void KateGotoBar::keyPressEvent(QKeyEvent *event) | ||
1103 | { | 1186 | { | ||
1104 | int key = event->key(); | 1187 | int key = event->key(); | ||
1105 | if (key == Qt::Key_Return || key == Qt::Key_Enter) { | 1188 | if (key == Qt::Key_Return || key == Qt::Key_Enter) { | ||
1106 | gotoLine(); | 1189 | gotoLine(); | ||
1107 | return; | 1190 | return; | ||
1108 | } | 1191 | } | ||
1109 | KateViewBarWidget::keyPressEvent(event); | 1192 | KateViewBarWidget::keyPressEvent(event); | ||
1110 | } | 1193 | } | ||
1111 | 1194 | | |||
1112 | void KateGotoBar::gotoLine() | 1195 | void KateGotoBar::gotoLine() | ||
1113 | { | 1196 | { | ||
1114 | KTextEditor::ViewPrivate *kv = qobject_cast<KTextEditor::ViewPrivate *>(m_view); | 1197 | KTextEditor::ViewPrivate *kv = qobject_cast<KTextEditor::ViewPrivate *>(m_view); | ||
1115 | if (kv && kv->selection() && !kv->config()->persistentSelection()) { | 1198 | if (kv && kv->selection() && !kv->config()->persistentSelection()) { | ||
1116 | kv->clearSelection(); | 1199 | kv->clearSelection(); | ||
1117 | } | 1200 | } | ||
1118 | 1201 | | |||
1119 | m_view->setCursorPosition(KTextEditor::Cursor(gotoRange->value() - 1, 0)); | 1202 | m_view->setCursorPosition(KTextEditor::Cursor(m_gotoRange->value() - 1, 0)); | ||
1120 | m_view->setFocus(); | 1203 | m_view->setFocus(); | ||
1121 | emit hideMe(); | 1204 | emit hideMe(); | ||
1122 | } | 1205 | } | ||
1123 | //END KateGotoBar | 1206 | //END KateGotoBar | ||
1124 | 1207 | | |||
1125 | //BEGIN KateDictionaryBar | 1208 | //BEGIN KateDictionaryBar | ||
1126 | KateDictionaryBar::KateDictionaryBar(KTextEditor::ViewPrivate *view, QWidget *parent) | 1209 | KateDictionaryBar::KateDictionaryBar(KTextEditor::ViewPrivate *view, QWidget *parent) | ||
1127 | : KateViewBarWidget(true, parent) | 1210 | : KateViewBarWidget(true, parent) | ||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |
Please always use QString() in favor of QStringLiteral("")