开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (16)
标签 (31)
master
coverity_scan
v3.11.x
issue1831_v1
qdarkstyle
no_savepoints_ro_db
v3.10.x
v3.9.x
v3.6.x
v3.5.x
v3.4.x
v3.3.x
utf8grammar
sqlb-3.2.x
sqlb-3.1.x
sqlb-3.x
continuous
v3.11.2
v3.11.1v2
v3.11.1
v3.11.0
v3.11.0-beta3
v3.11.0-beta2
v3.11.0-beta1
v3.11.0-alpha1
v3.10.1
v3.10.0
v3.10.0-beta2
v3.10.0-beta1
v3.9.1
v3.9.0
v3.9.0-beta1
v3.8.0
v3.7.0
v3.6.0
v3.5.1
master
分支 (16)
标签 (31)
master
coverity_scan
v3.11.x
issue1831_v1
qdarkstyle
no_savepoints_ro_db
v3.10.x
v3.9.x
v3.6.x
v3.5.x
v3.4.x
v3.3.x
utf8grammar
sqlb-3.2.x
sqlb-3.1.x
sqlb-3.x
continuous
v3.11.2
v3.11.1v2
v3.11.1
v3.11.0
v3.11.0-beta3
v3.11.0-beta2
v3.11.0-beta1
v3.11.0-alpha1
v3.10.1
v3.10.0
v3.10.0-beta2
v3.10.0-beta1
v3.9.1
v3.9.0
v3.9.0-beta1
v3.8.0
v3.7.0
v3.6.0
v3.5.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (16)
标签 (31)
master
coverity_scan
v3.11.x
issue1831_v1
qdarkstyle
no_savepoints_ro_db
v3.10.x
v3.9.x
v3.6.x
v3.5.x
v3.4.x
v3.3.x
utf8grammar
sqlb-3.2.x
sqlb-3.1.x
sqlb-3.x
continuous
v3.11.2
v3.11.1v2
v3.11.1
v3.11.0
v3.11.0-beta3
v3.11.0-beta2
v3.11.0-beta1
v3.11.0-alpha1
v3.10.1
v3.10.0
v3.10.0-beta2
v3.10.0-beta1
v3.9.1
v3.9.0
v3.9.0-beta1
v3.8.0
v3.7.0
v3.6.0
v3.5.1
sqlitebrowser
/
src
/
ExtendedScintilla.cpp
sqlitebrowser
/
src
/
ExtendedScintilla.cpp
ExtendedScintilla.cpp 11.60 KB
一键复制 编辑 原始数据 按行查看 历史
mgrojo 提交于 2019年07月27日 01:47 +08:00 . Allow using extended regular expressions in the find dialogs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
#include "ExtendedScintilla.h"
#include "FindReplaceDialog.h"
#include "Settings.h"
#include "Qsci/qscilexer.h"
#include "Qsci/qsciprinter.h"
#ifdef Q_OS_MACX
#include <Qsci/qscicommandset.h>
#include <Qsci/qscicommand.h>
#endif
#include <QFile>
#include <QDropEvent>
#include <QUrl>
#include <QMimeData>
#include <QShortcut>
#include <QAction>
#include <QMenu>
#include <QPalette>
#include <QPrintPreviewDialog>
#include <cmath>
ExtendedScintilla::ExtendedScintilla(QWidget* parent) :
QsciScintilla(parent),
findReplaceDialog(new FindReplaceDialog(this))
{
// This class does not set any lexer, that must be done in the child classes.
// Enable UTF8
setUtf8(true);
// Enable brace matching
setBraceMatching(QsciScintilla::SloppyBraceMatch);
// Enable auto indentation
setAutoIndent(true);
// Enable folding
setFolding(QsciScintilla::BoxedTreeFoldStyle);
// Create error indicator
errorIndicatorNumber = indicatorDefine(QsciScintilla::SquiggleIndicator);
setIndicatorForegroundColor(Qt::red, errorIndicatorNumber);
// Set a sensible scroll width, so the scroll bar is avoided in
// most cases.
setScrollWidth(80);
// Scroll width is adjusted to ensure that all of the lines
// currently displayed can be completely scrolled. This mode never
// adjusts the scroll width to be narrower.
setScrollWidthTracking(true);
// Visual flags for when wrap lines is enabled
setWrapVisualFlags(QsciScintilla::WrapFlagByBorder);
// Connect signals
connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth()));
// The shortcuts are constrained to the Widget context so they do not conflict with other SqlTextEdit widgets in the Main Window.
QShortcut* shortcutFindReplace = new QShortcut(QKeySequence(tr("Ctrl+H")), this, nullptr, nullptr, Qt::WidgetShortcut);
connect(shortcutFindReplace, SIGNAL(activated()), this, SLOT(openFindReplaceDialog()));
shortcutFind = new QShortcut(QKeySequence(tr("Ctrl+F")), this, nullptr, nullptr, Qt::WidgetShortcut);
connect(shortcutFind, SIGNAL(activated()), this, SLOT(openFindDialog()));
#ifdef Q_OS_MACX
// Alt+Backspace on Mac is expected to delete one word to the left,
// instead of undoing (default Scintilla binding).
QsciCommand * command = standardCommands()->find(QsciCommand::DeleteWordLeft);
command->setKey(Qt::AltModifier+Qt::Key_Backspace);
// And Cmd+Backspace should delete from cursor to the beginning of line
command = standardCommands()->find(QsciCommand::DeleteLineLeft);
command->setKey(Qt::ControlModifier+Qt::Key_Backspace);
#endif
QShortcut* shortcutPrint = new QShortcut(QKeySequence(tr("Ctrl+P")), this, nullptr, nullptr, Qt::WidgetShortcut);
connect(shortcutPrint, &QShortcut::activated, this, &ExtendedScintilla::openPrintDialog);
// Prepare for adding the find/replace option to the QScintilla context menu
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint &)));
}
ExtendedScintilla::~ExtendedScintilla()
{
}
void ExtendedScintilla::updateLineNumberAreaWidth()
{
// Calculate number of digits of the current number of lines
int digits = static_cast<int>(std::log10(lines())) + 1;
// Calculate the width of this number if it was all zeros (this is because a 1 might require less space than a 0 and this could
// cause some flickering depending on the font) and set the new margin width.
setMarginWidth(0, QFontMetrics(font()).width(QString("0").repeated(digits)) + 5);
}
void ExtendedScintilla::dropEvent(QDropEvent* e)
{
QList<QUrl> urls = e->mimeData()->urls();
if(urls.isEmpty())
return QsciScintilla::dropEvent(e);
QString file = urls.first().toLocalFile();
if(!QFile::exists(file))
return;
QFile f(file);
f.open(QIODevice::ReadOnly);
setText(f.readAll());
f.close();
}
void ExtendedScintilla::setupSyntaxHighlightingFormat(QsciLexer* lexer, const std::string& settings_name, int style)
{
lexer->setColor(QColor(Settings::getValue("syntaxhighlighter", settings_name + "_colour").toString()), style);
QFont font(Settings::getValue("editor", "font").toString());
font.setPointSize(Settings::getValue("editor", "fontsize").toInt());
font.setBold(Settings::getValue("syntaxhighlighter", settings_name + "_bold").toBool());
font.setItalic(Settings::getValue("syntaxhighlighter", settings_name + "_italic").toBool());
font.setUnderline(Settings::getValue("syntaxhighlighter", settings_name + "_underline").toBool());
lexer->setFont(font, style);
}
void ExtendedScintilla::setLexer(QsciLexer *lexer)
{
QsciScintilla::setLexer(lexer);
reloadCommonSettings();
}
void ExtendedScintilla::reloadCommonSettings()
{
// Set margins and default text colours according to settings. setLexer seems to reset these colours.
// Use desktop default colors for margins when following desktop
// style, or the colors matching the dark style-sheet, otherwise.
switch (Settings::getValue("General", "appStyle").toInt()) {
case Settings::FollowDesktopStyle :
setMarginsBackgroundColor(QPalette().color(QPalette::Active, QPalette::Window));
setMarginsForegroundColor(QPalette().color(QPalette::Active, QPalette::WindowText));
break;
case Settings::DarkStyle :
setMarginsBackgroundColor(QColor("#32414B"));
setMarginsForegroundColor(QColor("#EFF0F1"));
break;
}
setPaper(Settings::getValue("syntaxhighlighter", "background_colour").toString());
setColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString());
}
void ExtendedScintilla::reloadKeywords()
{
// Set lexer again to reload the updated keywords list
setLexer(lexer());
}
void ExtendedScintilla::reloadSettings()
{
reloadLexerSettings(lexer());
reloadKeywords();
}
void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer)
{
QColor foreground (Settings::getValue("syntaxhighlighter", "foreground_colour").toString());
QColor background (Settings::getValue("syntaxhighlighter", "background_colour").toString());
QFont defaultfont(Settings::getValue("editor", "font").toString());
defaultfont.setStyleHint(QFont::TypeWriter);
defaultfont.setPointSize(Settings::getValue("editor", "fontsize").toInt());
// Set syntax highlighting settings
if(lexer)
{
lexer->setFont(defaultfont);
lexer->setDefaultPaper(background);
lexer->setDefaultColor(foreground);
// This sets the base colors for all the styles
lexer->setPaper(background);
lexer->setColor(foreground);
}
// Set font
setFont(defaultfont);
// Show line numbers
setMarginsFont(defaultfont);
setMarginLineNumbers(0, true);
updateLineNumberAreaWidth();
// Highlight current line
setCaretLineVisible(true);
setCaretLineBackgroundColor(QColor(Settings::getValue("syntaxhighlighter", "currentline_colour").toString()));
setCaretForegroundColor(foreground);
// Set tab width
setTabWidth(Settings::getValue("editor", "tabsize").toInt());
if(lexer)
lexer->refreshProperties();
// Check if error indicators are enabled and clear them if they just got disabled
showErrorIndicators = Settings::getValue("editor", "error_indicators").toBool();
if(!showErrorIndicators)
clearErrorIndicators();
}
void ExtendedScintilla::clearErrorIndicators()
{
// Clear any error indicators from position (0,0) to the last column of the last line
clearIndicatorRange(0, 0, lines(), lineLength(lines()), errorIndicatorNumber);
}
void ExtendedScintilla::setErrorIndicator(int fromRow, int fromIndex, int toRow, int toIndex)
{
// Set error indicator for the specified range but only if they're enabled
if(showErrorIndicators)
fillIndicatorRange(fromRow, fromIndex, toRow, toIndex, errorIndicatorNumber);
}
void ExtendedScintilla::setErrorIndicator(int position)
{
// Set error indicator for the position until end of line, but only if they're enabled
if(showErrorIndicators) {
int column = static_cast<int>(SendScintilla(QsciScintillaBase::SCI_GETCOLUMN, position));
int line = static_cast<int>(SendScintilla(QsciScintillaBase::SCI_LINEFROMPOSITION, position));
fillIndicatorRange(line, column, line+1, 0, errorIndicatorNumber);
}
}
bool ExtendedScintilla::findText(QString text, bool regexp, bool caseSensitive, bool words, bool wrap, bool forward) {
// For finding the previous occurrence, we need to skip the current
// selection, otherwise we'd always found the same occurrence.
if (!forward && hasSelectedText()) {
int lineFrom, indexFrom;
int lineTo, indexTo;
getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo);
setCursorPosition(lineFrom, indexFrom);
}
return findFirst(text, regexp, caseSensitive, words, wrap, forward,
/* line */ -1, /* index */ -1,
/* show */ true, /* posix */ true, /* cxx11 */ true);
}
void ExtendedScintilla::setEnabledFindDialog(bool value)
{
shortcutFind->setEnabled(value);
}
void ExtendedScintilla::clearSelection()
{
setSelection(-1,-1,-1,-1);
}
void ExtendedScintilla::openFindReplaceDialog()
{
findReplaceDialog->setExtendedScintilla(this);
findReplaceDialog->showFindReplaceDialog(true);
}
void ExtendedScintilla::openFindDialog()
{
findReplaceDialog->setExtendedScintilla(this);
findReplaceDialog->showFindReplaceDialog(false);
}
void ExtendedScintilla::showContextMenu(const QPoint &pos)
{
// This has to be created here, otherwise the set of enabled options would not update accordingly.
QMenu* editContextMenu = createStandardContextMenu();
editContextMenu->addSeparator();
if (shortcutFind->isEnabled()) {
QAction* findAction = new QAction(QIcon(":/icons/find"), tr("Find..."), this);
findAction->setShortcut(shortcutFind->key());
connect(findAction, &QAction::triggered, this, &ExtendedScintilla::openFindDialog);
editContextMenu->addAction(findAction);
}
QAction* findReplaceAction = new QAction(QIcon(":/icons/text_replace"), tr("Find and Replace..."), this);
findReplaceAction->setShortcut(QKeySequence(tr("Ctrl+H")));
connect(findReplaceAction, &QAction::triggered, this, &ExtendedScintilla::openFindReplaceDialog);
QAction* printAction = new QAction(QIcon(":/icons/print"), tr("Print..."), this);
printAction->setShortcut(QKeySequence(tr("Ctrl+P")));
connect(printAction, &QAction::triggered, this, &ExtendedScintilla::openPrintDialog);
editContextMenu->addAction(findReplaceAction);
editContextMenu->addSeparator();
editContextMenu->addAction(printAction);
editContextMenu->exec(mapToGlobal(pos));
}
void ExtendedScintilla::openPrintDialog()
{
QsciPrinter printer;
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
QsciPrinter* sciPrinter = static_cast<QsciPrinter*>(previewPrinter);
sciPrinter->printRange(this);
});
dialog->exec();
delete dialog;
}
void ExtendedScintilla::setReadOnly(bool ro)
{
QsciScintilla::setReadOnly(ro);
// Disable or enable caret blinking so it is obvious whether the text can be modified or not. Otherwise there isn't any other hint.
SendScintilla(QsciScintillaBase::SCI_SETCARETPERIOD, ro ? 0 : 500);
}
void ExtendedScintilla::setText(const QString& text)
{
// Reset scroll width, so the scroll bar is readjusted to the new text.
// Otherwise, it grows always bigger.
setScrollWidth(80);
QsciScintilla::setText(text);
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Official home of the DB Browser for SQLite (DB4S) project. Previously known as "SQLite Database Browser" and "Database Browser for SQLite". Website at:
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/ax4688/sqlitebrowser.git
git@gitee.com:ax4688/sqlitebrowser.git
ax4688
sqlitebrowser
sqlitebrowser
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /