Skip to content
Permalink
Browse files

Make highlightable line edit its own widget - QgsHighlightableLineEdit

  • Loading branch information
nyalldawson committed Mar 25, 2020
1 parent a2fb472 commit 9e4e32ffa4bce2bb5e2ce209d1e4d7806badb98d
@@ -0,0 +1,54 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgshighlightablelineedit.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsHighlightableLineEdit: QgsFilterLineEdit
{
%Docstring

A QgsFilterLineEdit subclass with the ability to "highlight" the edges of the widget.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgshighlightablelineedit.h"
%End
public:
QgsHighlightableLineEdit( QWidget *parent /TransferThis/ = 0 );

bool isHighlighted() const;
%Docstring
Returns ``True`` if the line edit is currently highlighted.

.. seealso:: :py:func:`setHighlighted`
%End

void setHighlighted( bool highlighted );
%Docstring
Sets whether the line edit is currently ``highlighted``.

.. seealso:: :py:func:`isHighlighted`
%End

protected:
virtual void paintEvent( QPaintEvent *e );


};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgshighlightablelineedit.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -99,6 +99,7 @@
%Include auto_generated/qgsgui.sip
%Include auto_generated/qgshelp.sip
%Include auto_generated/qgshighlight.sip
%Include auto_generated/qgshighlightablelineedit.sip
%Include auto_generated/qgshistogramwidget.sip
%Include auto_generated/qgsidentifymenu.sip
%Include auto_generated/qgskeyvaluewidget.sip
@@ -406,6 +406,7 @@ SET(QGIS_GUI_SRCS
qgsguiutils.cpp
qgshighlight.cpp
qgshighlightablecombobox.cpp
qgshighlightablelineedit.cpp
qgshistogramwidget.cpp
qgshelp.cpp
qgsidentifymenu.cpp
@@ -626,6 +627,7 @@ SET(QGIS_GUI_HDRS
qgshelp.h
qgshighlight.h
qgshighlightablecombobox.h
qgshighlightablelineedit.h
qgshistogramwidget.h
qgsidentifymenu.h
qgsinstallgridshiftdialog.h
@@ -408,9 +408,8 @@ QString QgsFileWidget::toUrl( const QString &path ) const


QgsFileDropEdit::QgsFileDropEdit( QWidget *parent )
: QgsFilterLineEdit( parent )
: QgsHighlightableLineEdit( parent )
{
mDragActive = false;
setAcceptDrops( true );
}

@@ -510,8 +509,7 @@ void QgsFileDropEdit::dragEnterEvent( QDragEnterEvent *event )
if ( !filePath.isEmpty() )
{
event->acceptProposedAction();
mDragActive = true;
update();
setHighlighted( true );
}
else
{
@@ -523,8 +521,7 @@ void QgsFileDropEdit::dragLeaveEvent( QDragLeaveEvent *event )
{
QgsFilterLineEdit::dragLeaveEvent( event );
event->accept();
mDragActive = false;
update();
setHighlighted( false );
}

void QgsFileDropEdit::dropEvent( QDropEvent *event )
@@ -536,21 +533,7 @@ void QgsFileDropEdit::dropEvent( QDropEvent *event )
selectAll();
setFocus( Qt::MouseFocusReason );
event->acceptProposedAction();
mDragActive = false;
update();
}
}

void QgsFileDropEdit::paintEvent( QPaintEvent *e )
{
QgsFilterLineEdit::paintEvent( e );
if ( mDragActive )
{
QPainter p( this );
int width = 2; // width of highlight rectangle inside frame
p.setPen( QPen( palette().highlight(), width ) );
QRect r = rect().adjusted( width, width, -width, -width );
p.drawRect( r );
setHighlighted( false );
}
}

@@ -26,7 +26,7 @@ class QHBoxLayout;

#include "qgis_gui.h"
#include "qgis_sip.h"
#include "qgsfilterlineedit.h"
#include "qgshighlightablelineedit.h"

/**
* \ingroup gui
@@ -243,7 +243,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
* or directories only. By default, dropping is limited to files only.
* \note not available in Python bindings
*/
class GUI_EXPORT QgsFileDropEdit: public QgsFilterLineEdit
class GUI_EXPORT QgsFileDropEdit: public QgsHighlightableLineEdit
{
Q_OBJECT

@@ -259,7 +259,6 @@ class GUI_EXPORT QgsFileDropEdit: public QgsFilterLineEdit
void dragEnterEvent( QDragEnterEvent *event ) override;
void dragLeaveEvent( QDragLeaveEvent *event ) override;
void dropEvent( QDropEvent *event ) override;
void paintEvent( QPaintEvent *e ) override;

private:

@@ -268,7 +267,6 @@ class GUI_EXPORT QgsFileDropEdit: public QgsFilterLineEdit

QStringList mAcceptableExtensions;
QgsFileWidget::StorageMode mStorageMode = QgsFileWidget::GetFile;
bool mDragActive;
friend class TestQgsFileWidget;
};

@@ -0,0 +1,41 @@
/***************************************************************************
qgshighlightablelineedit.h
-------------------------
Date : March 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/


#include "qgshighlightablelineedit.h"
#include <QPainter>

QgsHighlightableLineEdit::QgsHighlightableLineEdit( QWidget *parent )
: QgsFilterLineEdit( parent )
{}

void QgsHighlightableLineEdit::paintEvent( QPaintEvent *e )
{
QgsFilterLineEdit::paintEvent( e );
if ( mHighlight )
{
QPainter p( this );
int width = 2; // width of highlight rectangle inside frame
p.setPen( QPen( palette().highlight(), width ) );
QRect r = rect().adjusted( width, width, -width, -width );
p.drawRect( r );
}
}

void QgsHighlightableLineEdit::setHighlighted( bool highlighted )
{
mHighlight = highlighted;
update();
}
@@ -0,0 +1,61 @@
/***************************************************************************
qgshighlightablelineedit.h
-------------------------
Date : March 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSHIGHLIGHTABLELINEEDIT_H
#define QGSHIGHLIGHTABLELINEEDIT_H

#include <QWidget>

#include "qgis_gui.h"
#include "qgis_sip.h"
#include "qgsfilterlineedit.h"

/**
* \class QgsHighlightableLineEdit
* \ingroup gui
*
* A QgsFilterLineEdit subclass with the ability to "highlight" the edges of the widget.
*
* \since QGIS 3.14
*/
class GUI_EXPORT QgsHighlightableLineEdit: public QgsFilterLineEdit
{
Q_OBJECT

public:
QgsHighlightableLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );

/**
* Returns TRUE if the line edit is currently highlighted.
* \see setHighlighted()
*/
bool isHighlighted() const { return mHighlight; }

/**
* Sets whether the line edit is currently \a highlighted.
* \see isHighlighted()
*/
void setHighlighted( bool highlighted );

protected:
void paintEvent( QPaintEvent *e ) override;

private:

bool mHighlight = false;
};


#endif // QGSHIGHLIGHTABLELINEEDIT_H

0 comments on commit 9e4e32f

Please sign in to comment.
You can’t perform that action at this time.