Skip to content

Commit

Permalink
Some minor cleaning up (#1414).
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed May 22, 2018
1 parent a916e6e commit aa0f797
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 83 deletions.
43 changes: 1 addition & 42 deletions src/plugins/widget/EditorWidget/src/editorwidget.cpp
Expand Up @@ -58,7 +58,7 @@ EditorWidget::EditorWidget(const QString &pContents, bool pReadOnly,
mSeparator = Core::newLineWidget(this);
mFindReplace = new EditorWidgetFindReplaceWidget(this);

mEditor = new EditorWidgetEditorWidget(pLexer, this, mFindReplace, this);
mEditor = new EditorWidgetEditorWidget(pLexer, mFindReplace, this);

// Set our contents and our read-only state

Expand Down Expand Up @@ -87,11 +87,6 @@ EditorWidget::EditorWidget(const QString &pContents, bool pReadOnly,
connect(mEditor, SIGNAL(canSelectAll(bool)),
this, SIGNAL(canSelectAll(bool)));

// Keep track of whenever a key is being pressed in our find/replace widget

connect(mFindReplace, &EditorWidgetFindReplaceWidget::keyPressed,
this, &EditorWidget::findReplaceKeyPressed);

// Keep track of whenever the find text changes

connect(mFindReplace, &EditorWidgetFindReplaceWidget::findTextChanged,
Expand Down Expand Up @@ -607,42 +602,6 @@ bool EditorWidget::findPrevious()

//==============================================================================

void EditorWidget::findReplaceKeyPressed(QKeyEvent *pEvent, bool &pHandled)
{
// Some key combinations from our find/replace widget

if ( !(pEvent->modifiers() & Qt::ShiftModifier)
&& !(pEvent->modifiers() & Qt::ControlModifier)
&& !(pEvent->modifiers() & Qt::AltModifier)
&& !(pEvent->modifiers() & Qt::MetaModifier)
&& (pEvent->key() == Qt::Key_Escape)) {
hideFindReplace();

pHandled = true;
} else if ( !(pEvent->modifiers() & Qt::ShiftModifier)
&& !(pEvent->modifiers() & Qt::ControlModifier)
&& !(pEvent->modifiers() & Qt::AltModifier)
&& !(pEvent->modifiers() & Qt::MetaModifier)
&& ( (pEvent->key() == Qt::Key_Return)
|| (pEvent->key() == Qt::Key_Enter))) {
if (mFindReplace->findEditHasFocus()) {
mEditor->findNext();

pHandled = true;
} else if (mFindReplace->replaceEditHasFocus()) {
mEditor->replaceAndFind();

pHandled = true;
} else {
pHandled = false;
}
} else {
pHandled = false;
}
}

//==============================================================================

void EditorWidget::hideFindReplace()
{
// Hide our find/replace widget
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/widget/EditorWidget/src/editorwidget.h
Expand Up @@ -148,9 +148,7 @@ class EDITORWIDGET_EXPORT EditorWidget : public Core::Widget

void canSelectAll(bool pCanSelectAll);

private slots:
void findReplaceKeyPressed(QKeyEvent *pEvent, bool &pHandled);

public slots:
void hideFindReplace();
};

Expand Down
Expand Up @@ -40,11 +40,10 @@ namespace EditorWidget {
//==============================================================================

EditorWidgetEditorWidget::EditorWidgetEditorWidget(QsciLexer *pLexer,
EditorWidget *pOwner,
EditorWidgetFindReplaceWidget *pFindReplace,
QWidget *pParent) :
EditorWidget *pParent) :
QScintillaSupport::QScintillaWidget(pLexer, pParent),
mOwner(pOwner),
mOwner(pParent),
mFindReplace(pFindReplace),
mReadOnlyStyles(QIntList()),
mHighlightedLines(QIntList())
Expand Down
Expand Up @@ -47,9 +47,9 @@ class EDITORWIDGET_EXPORT EditorWidgetEditorWidget : public QScintillaSupport::Q
Q_OBJECT

public:
explicit EditorWidgetEditorWidget(QsciLexer *pLexer, EditorWidget *pOwner,
explicit EditorWidgetEditorWidget(QsciLexer *pLexer,
EditorWidgetFindReplaceWidget *pFindReplace,
QWidget *pParent);
EditorWidget *pParent);

void setReadOnly(bool pReadOnly) override;

Expand Down
Expand Up @@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//==============================================================================

#include "coreguiutils.h"
#include "editorwidget.h"
#include "editorwidgeteditorwidget.h"
#include "editorwidgetfindreplacewidget.h"
#include "i18ninterface.h"

Expand Down Expand Up @@ -50,9 +52,10 @@ namespace EditorWidget {

//==============================================================================

EditorWidgetFindReplaceWidget::EditorWidgetFindReplaceWidget(QWidget *pParent) :
EditorWidgetFindReplaceWidget::EditorWidgetFindReplaceWidget(EditorWidget *pParent) :
Core::Widget(pParent),
mGui(new Ui::EditorWidgetFindReplaceWidget),
mOwner(pParent),
mActive(false)
{
// Set up the GUI
Expand Down Expand Up @@ -297,24 +300,6 @@ QString EditorWidgetFindReplaceWidget::replaceText() const

//==============================================================================

bool EditorWidgetFindReplaceWidget::findEditHasFocus() const
{
// Return whether our find edit has the focus

return mGui->findEdit->hasFocus();
}

//==============================================================================

bool EditorWidgetFindReplaceWidget::replaceEditHasFocus() const
{
// Return whether our replace edit has the focus

return mGui->replaceEdit->hasFocus();
}

//==============================================================================

bool EditorWidgetFindReplaceWidget::isActive() const
{
// Return whether we are active
Expand Down Expand Up @@ -415,18 +400,40 @@ void EditorWidgetFindReplaceWidget::changeEvent(QEvent *pEvent)

void EditorWidgetFindReplaceWidget::keyPressEvent(QKeyEvent *pEvent)
{
// Let people know that a key has been pressed

bool handled = false;
// Some key combinations from our find/replace widget

emit keyPressed(pEvent, handled);
if ( !(pEvent->modifiers() & Qt::ShiftModifier)
&& !(pEvent->modifiers() & Qt::ControlModifier)
&& !(pEvent->modifiers() & Qt::AltModifier)
&& !(pEvent->modifiers() & Qt::MetaModifier)
&& (pEvent->key() == Qt::Key_Escape)) {
mOwner->hideFindReplace();

// Accept the event or carry on as normal, if the event wasn't handled

if (handled)
pEvent->accept();
else
} else if ( !(pEvent->modifiers() & Qt::ShiftModifier)
&& !(pEvent->modifiers() & Qt::ControlModifier)
&& !(pEvent->modifiers() & Qt::AltModifier)
&& !(pEvent->modifiers() & Qt::MetaModifier)
&& ( (pEvent->key() == Qt::Key_Return)
|| (pEvent->key() == Qt::Key_Enter))) {
if (mGui->findEdit->hasFocus()) {
mOwner->editor()->findNext();

pEvent->accept();
} else if (mGui->replaceEdit->hasFocus()) {
mOwner->editor()->replaceAndFind();

pEvent->accept();
} else {
// Default handling of the event

Core::Widget::keyPressEvent(pEvent);
}
} else {
// Default handling of the event

Core::Widget::keyPressEvent(pEvent);
}
}

//==============================================================================
Expand Down
Expand Up @@ -50,12 +50,16 @@ namespace EditorWidget {

//==============================================================================

class EditorWidget;

//==============================================================================

class EditorWidgetFindReplaceWidget : public Core::Widget
{
Q_OBJECT

public:
explicit EditorWidgetFindReplaceWidget(QWidget *pParent);
explicit EditorWidgetFindReplaceWidget(EditorWidget *pParent);
~EditorWidgetFindReplaceWidget() override;

void retranslateUi() override;
Expand All @@ -77,9 +81,6 @@ class EditorWidgetFindReplaceWidget : public Core::Widget

QString replaceText() const;

bool findEditHasFocus() const;
bool replaceEditHasFocus() const;

bool isActive() const;
void setActive(bool pActive);

Expand All @@ -91,6 +92,8 @@ class EditorWidgetFindReplaceWidget : public Core::Widget
private:
Ui::EditorWidgetFindReplaceWidget *mGui;

EditorWidget *mOwner;

QAction *mDropDownAction;

QAction *mCaseSensitiveAction;
Expand All @@ -106,8 +109,6 @@ class EditorWidgetFindReplaceWidget : public Core::Widget
void updateStyleSheet();

signals:
void keyPressed(QKeyEvent *pEvent, bool &pHandled);

void findTextChanged(const QString &pText);

void canFindReplace(bool pCanFindReplace);
Expand Down

0 comments on commit aa0f797

Please sign in to comment.