2021-09-01 13:58:59 -05:00
|
|
|
#include "SeerEditorWidget.h"
|
|
|
|
|
#include <QtGui/QColor>
|
|
|
|
|
#include <QtGui/QPainter>
|
|
|
|
|
#include <QtGui/QTextBlock>
|
|
|
|
|
#include <QtGui/QFont>
|
|
|
|
|
#include <QtGui/QIcon>
|
|
|
|
|
#include <QtGui/QRadialGradient>
|
|
|
|
|
#include <QtWidgets/QScrollBar>
|
2022-01-20 10:40:56 -06:00
|
|
|
#include <QtWidgets/QFileDialog>
|
2021-09-01 13:58:59 -05:00
|
|
|
#include <QtWidgets/QMenu>
|
|
|
|
|
#include <QtWidgets/QAction>
|
|
|
|
|
#include <QtGui/QTextCursor>
|
|
|
|
|
#include <QtGui/QPalette>
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
2022-02-24 17:54:31 -06:00
|
|
|
SeerEditorWidget::SeerEditorWidget(QWidget* parent) : QWidget(parent) {
|
2021-09-01 13:58:59 -05:00
|
|
|
|
|
|
|
|
// Construct the UI.
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
|
|
// Set the widgets.
|
2021-09-10 15:32:23 -05:00
|
|
|
int space = fontMetrics().horizontalAdvance("Go to line ##") + 5;
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
searchLineNumberLineEdit->setMaximumWidth(space);
|
2022-06-26 11:04:25 -05:00
|
|
|
searchTextLineEdit->enableReturnPressedOnClear();
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
showSearchBar(false); // Hide the search bar. ctrl+F to show it again.
|
|
|
|
|
showAlternateBar(false); // Hide the alternate bar. ctrl+O to show it again.
|
|
|
|
|
setSearchMatchCase(true); // Search with case sensitivity.
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-02-27 18:30:15 -06:00
|
|
|
_textSearchShortcut = new QShortcut(QKeySequence(tr("Ctrl+F")), this);
|
|
|
|
|
_textSearchNextShortcut = new QShortcut(QKeySequence(tr("Ctrl+G")), this);
|
|
|
|
|
_textSearchPrevShortcut = new QShortcut(QKeySequence(tr("Ctrl+Shift+G")), this);
|
|
|
|
|
_alternateDirShortcut = new QShortcut(QKeySequence(tr("Ctrl+O")), this);
|
2022-02-24 17:54:31 -06:00
|
|
|
|
|
|
|
|
setKeySettings(SeerKeySettings::populate());
|
2022-02-24 16:53:27 -06:00
|
|
|
|
2021-09-01 13:58:59 -05:00
|
|
|
// Connect things.
|
2022-01-24 13:37:37 -06:00
|
|
|
QObject::connect(searchTextLineEdit, &QLineEdit::returnPressed, this, &SeerEditorWidget::handleSearchTextLineEdit);
|
2022-02-27 13:17:11 -06:00
|
|
|
QObject::connect(matchCaseCheckBox, &QCheckBox::stateChanged, this, &SeerEditorWidget::handleSearchTextLineEdit);
|
2022-01-24 13:37:37 -06:00
|
|
|
QObject::connect(searchDownToolButton, &QToolButton::clicked, this, &SeerEditorWidget::handleSearchDownToolButton);
|
|
|
|
|
QObject::connect(searchUpToolButton, &QToolButton::clicked, this, &SeerEditorWidget::handleSearchUpToolButton);
|
|
|
|
|
QObject::connect(searchLineNumberLineEdit, &QLineEdit::returnPressed, this, &SeerEditorWidget::handleSearchLineNumberLineEdit);
|
|
|
|
|
QObject::connect(searchCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidget::handleSearchCloseToolButton);
|
|
|
|
|
QObject::connect(alternateCloseToolButton, &QToolButton::clicked, this, &SeerEditorWidget::handleAlternateCloseToolButton);
|
|
|
|
|
QObject::connect(alternateFileOpenToolButton, &QToolButton::clicked, this, &SeerEditorWidget::handleAlternateFileOpenToolButton);
|
|
|
|
|
QObject::connect(alternateAddToGlobalToolButton, &QToolButton::clicked, this, &SeerEditorWidget::handleAlternateAddToGlobalToolButton);
|
|
|
|
|
QObject::connect(alternateLineEdit, &QLineEdit::returnPressed, this, &SeerEditorWidget::handleAlternateLineEdit);
|
|
|
|
|
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showSearchBar, this, &SeerEditorWidget::showSearchBar);
|
|
|
|
|
QObject::connect(sourceWidget, &SeerEditorWidgetSourceArea::showAlternateBar, this, &SeerEditorWidget::showAlternateBar);
|
2022-02-24 16:53:27 -06:00
|
|
|
|
|
|
|
|
QObject::connect(_textSearchShortcut, &QShortcut::activated, this, &SeerEditorWidget::handleTextSearchShortcut);
|
2022-02-27 18:30:15 -06:00
|
|
|
QObject::connect(_textSearchNextShortcut, &QShortcut::activated, this, &SeerEditorWidget::handleSearchDownToolButton);
|
|
|
|
|
QObject::connect(_textSearchPrevShortcut, &QShortcut::activated, this, &SeerEditorWidget::handleSearchUpToolButton);
|
2022-02-24 17:54:31 -06:00
|
|
|
QObject::connect(_alternateDirShortcut, &QShortcut::activated, this, &SeerEditorWidget::handleAlternateDirectoryShortcut);
|
2021-09-01 13:58:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeerEditorWidget::~SeerEditorWidget () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeerEditorWidgetSourceArea* SeerEditorWidget::sourceArea () {
|
|
|
|
|
return sourceWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
bool SeerEditorWidget::isSearchBarShown () const {
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
bool shown = false;
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
// Go through the widgets in the search bar to see if any are visable.
|
|
|
|
|
for (int i = 0; i != searchBarLayout->count(); ++i) {
|
|
|
|
|
QWidget* w = searchBarLayout->itemAt(i)->widget();
|
|
|
|
|
if (w != 0) {
|
|
|
|
|
if (w->isVisible()) {
|
|
|
|
|
shown = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-01 13:58:59 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
return shown;
|
2021-09-01 13:58:59 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
bool SeerEditorWidget::searchMatchCase () const {
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
return matchCaseCheckBox->isChecked();
|
2021-09-01 13:58:59 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
bool SeerEditorWidget::isAlternateBarShown () const {
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
bool shown = false;
|
2021-09-01 13:58:59 -05:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
// Go through the widgets in the search bar to see if any are visable.
|
|
|
|
|
for (int i = 0; i != alternateBarLayout->count(); ++i) {
|
|
|
|
|
QWidget* w = alternateBarLayout->itemAt(i)->widget();
|
|
|
|
|
if (w != 0) {
|
|
|
|
|
if (w->isVisible()) {
|
|
|
|
|
shown = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-01 13:58:59 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
return shown;
|
2021-09-01 13:58:59 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 17:54:31 -06:00
|
|
|
void SeerEditorWidget::setKeySettings (const SeerKeySettings& settings) {
|
|
|
|
|
|
|
|
|
|
_keySettings = settings;
|
|
|
|
|
|
|
|
|
|
if (_keySettings.has("SearchText") == true) {
|
|
|
|
|
_textSearchShortcut->setKey(_keySettings.get("SearchText")._sequence);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-27 18:30:15 -06:00
|
|
|
if (_keySettings.has("SearchTextNext") == true) {
|
|
|
|
|
_textSearchNextShortcut->setKey(_keySettings.get("SearchTextNext")._sequence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_keySettings.has("SearchTextPrev") == true) {
|
|
|
|
|
_textSearchPrevShortcut->setKey(_keySettings.get("SearchTextPrev")._sequence);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 17:54:31 -06:00
|
|
|
if (_keySettings.has("AlternateDir") == true) {
|
|
|
|
|
_alternateDirShortcut->setKey(_keySettings.get("AlternateDir")._sequence);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SeerKeySettings& SeerEditorWidget::keySettings () const {
|
|
|
|
|
|
|
|
|
|
return _keySettings;
|
|
|
|
|
}
|
2021-09-01 13:58:59 -05:00
|
|
|
|
|
|
|
|
void SeerEditorWidget::showSearchBar (bool flag) {
|
|
|
|
|
|
|
|
|
|
// Go through the widgets in the search bar and hide/show them.
|
|
|
|
|
for (int i = 0; i != searchBarLayout->count(); ++i) {
|
|
|
|
|
QWidget* w = searchBarLayout->itemAt(i)->widget();
|
|
|
|
|
if (w != 0) {
|
|
|
|
|
w->setVisible(flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If 'show', give the searchTextLineEdit the focus.
|
|
|
|
|
if (flag) {
|
|
|
|
|
searchTextLineEdit->setFocus(Qt::MouseFocusReason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the layout.
|
|
|
|
|
searchBarLayout->update();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
void SeerEditorWidget::setSearchMatchCase (bool flag) {
|
2021-12-13 19:57:37 -06:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
matchCaseCheckBox->setChecked(flag);
|
2021-12-13 19:57:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerEditorWidget::showAlternateBar (bool flag) {
|
|
|
|
|
|
2022-01-22 11:34:42 -06:00
|
|
|
// Set the label's text.
|
|
|
|
|
alternateLabel->setText("Enter directory path for '" + sourceArea()->file() + "'");
|
|
|
|
|
|
2021-12-13 19:57:37 -06:00
|
|
|
// Go through the widgets in the search bar and hide/show them.
|
|
|
|
|
for (int i = 0; i != alternateBarLayout->count(); ++i) {
|
|
|
|
|
QWidget* w = alternateBarLayout->itemAt(i)->widget();
|
|
|
|
|
if (w != 0) {
|
|
|
|
|
w->setVisible(flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-27 13:17:11 -06:00
|
|
|
// If 'show', give the alternateLineEdit the focus.
|
2021-12-13 19:57:37 -06:00
|
|
|
if (flag) {
|
|
|
|
|
alternateLineEdit->setFocus(Qt::MouseFocusReason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the layout.
|
|
|
|
|
alternateBarLayout->update();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
void SeerEditorWidget::handleSearchLineNumberLineEdit () {
|
2021-12-13 19:57:37 -06:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
QString str = searchLineNumberLineEdit->text();
|
2021-12-13 19:57:37 -06:00
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
if (str == "") {
|
|
|
|
|
return;
|
2021-12-13 19:57:37 -06:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
int lineno = str.toInt();
|
|
|
|
|
|
|
|
|
|
if (lineno < 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchLineNumberLineEdit->clear();
|
|
|
|
|
|
|
|
|
|
sourceArea()->scrollToLine(lineno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerEditorWidget::handleSearchTextLineEdit () {
|
|
|
|
|
|
|
|
|
|
QString str = searchTextLineEdit->text();
|
|
|
|
|
|
2022-02-27 13:17:11 -06:00
|
|
|
matchesLabel->setText("");
|
|
|
|
|
|
2022-02-24 16:38:12 -06:00
|
|
|
if (str == "") {
|
2022-02-27 13:17:11 -06:00
|
|
|
sourceArea()->clearFindText();
|
2022-02-24 16:38:12 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 20:20:37 -05:00
|
|
|
int nMatches = sourceArea()->findText(str, (searchMatchCase() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags()));
|
2022-02-27 13:17:11 -06:00
|
|
|
|
|
|
|
|
matchesLabel->setText(QString("(%1)").arg(nMatches));
|
2022-02-24 16:38:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerEditorWidget::handleSearchDownToolButton () {
|
|
|
|
|
|
|
|
|
|
QString str = searchTextLineEdit->text();
|
|
|
|
|
|
|
|
|
|
if (str == "") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 20:20:37 -05:00
|
|
|
sourceArea()->find(str, (searchMatchCase() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags()));
|
2022-02-24 16:38:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerEditorWidget::handleSearchUpToolButton () {
|
|
|
|
|
|
|
|
|
|
QString str = searchTextLineEdit->text();
|
|
|
|
|
|
|
|
|
|
if (str == "") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 20:20:37 -05:00
|
|
|
sourceArea()->find(str, (searchMatchCase() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags()) | QTextDocument::FindBackward);
|
2021-12-13 19:57:37 -06:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
void SeerEditorWidget::handleSearchCloseToolButton () {
|
2021-09-01 13:58:59 -05:00
|
|
|
showSearchBar(false);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:40:56 -06:00
|
|
|
void SeerEditorWidget::handleAlternateCloseToolButton () {
|
|
|
|
|
showAlternateBar(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerEditorWidget::handleAlternateFileOpenToolButton () {
|
|
|
|
|
|
2022-01-20 19:11:15 -06:00
|
|
|
//qDebug() << "fullname =" << sourceArea()->fullname();
|
|
|
|
|
//qDebug() << "file =" << sourceArea()->file();
|
2022-01-20 10:40:56 -06:00
|
|
|
|
2022-01-20 19:11:15 -06:00
|
|
|
QString filename = QFileDialog::getOpenFileName(this, "Locate File", sourceArea()->fullname(), QString("File (%1)").arg(sourceArea()->file()), nullptr, QFileDialog::DontUseNativeDialog);
|
2022-01-20 10:40:56 -06:00
|
|
|
|
2022-01-20 19:11:15 -06:00
|
|
|
//qDebug() << "location =" << filename;
|
|
|
|
|
//qDebug() << "directory=" << QFileInfo(filename).absolutePath();
|
|
|
|
|
|
|
|
|
|
if (filename != "") {
|
|
|
|
|
alternateLineEdit->setText(QFileInfo(filename).absolutePath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 13:37:37 -06:00
|
|
|
void SeerEditorWidget::handleAlternateLineEdit () {
|
2022-01-20 19:11:15 -06:00
|
|
|
|
|
|
|
|
showAlternateBar(false);
|
|
|
|
|
|
|
|
|
|
QString dirname = alternateLineEdit->text();
|
|
|
|
|
|
|
|
|
|
//qDebug() << "alternate dirname=" << dirname;
|
|
|
|
|
|
2022-01-22 11:34:42 -06:00
|
|
|
sourceArea()->open(sourceArea()->fullname(), sourceArea()->file(), dirname);
|
2022-01-20 10:40:56 -06:00
|
|
|
}
|
|
|
|
|
|
2022-01-24 13:37:37 -06:00
|
|
|
void SeerEditorWidget::handleAlternateAddToGlobalToolButton () {
|
|
|
|
|
|
|
|
|
|
if (alternateLineEdit->text() == "") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//qDebug() << "alternate dirname=" << alternateLineEdit->text();
|
|
|
|
|
|
|
|
|
|
emit addAlternateDirectory(alternateLineEdit->text());
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 16:53:27 -06:00
|
|
|
void SeerEditorWidget::handleTextSearchShortcut () {
|
|
|
|
|
|
|
|
|
|
if (isSearchBarShown() == true) {
|
|
|
|
|
showSearchBar(false);
|
|
|
|
|
}else{
|
|
|
|
|
showSearchBar(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeerEditorWidget::handleAlternateDirectoryShortcut () {
|
|
|
|
|
|
|
|
|
|
if (isAlternateBarShown() == true) {
|
|
|
|
|
showAlternateBar(false);
|
|
|
|
|
}else{
|
|
|
|
|
showAlternateBar(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|