-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4670 from nyalldawson/widget_action_header
New classes QgsMenuHeader, QgsMenuHeaderWidgetAction
- Loading branch information
Showing
5 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsmenuheader.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsMenuHeader : QWidget | ||
{ | ||
%Docstring | ||
Custom widget for displaying subheaders within a QMenu in a standard style. | ||
.. versionadded:: 3.0 | ||
.. seealso:: QgsMenuHeaderWidgetAction() | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmenuheader.h" | ||
%End | ||
public: | ||
|
||
explicit QgsMenuHeader( const QString &text, QWidget *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Constructor for QgsMenuHeader, showing the specified ``text``. | ||
%End | ||
|
||
virtual QSize minimumSizeHint() const; | ||
virtual QSize sizeHint() const; | ||
|
||
protected: | ||
|
||
virtual void paintEvent( QPaintEvent *event ); | ||
|
||
|
||
}; | ||
|
||
class QgsMenuHeaderWidgetAction: QWidgetAction | ||
{ | ||
%Docstring | ||
Custom QWidgetAction for displaying subheaders within a QMenu in a standard style. | ||
.. versionadded:: 3.0 | ||
.. seealso:: QgsMenuHeader() | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmenuheader.h" | ||
%End | ||
public: | ||
|
||
QgsMenuHeaderWidgetAction( const QString &text, QObject *parent = 0 ); | ||
%Docstring | ||
Constructor for QgsMenuHeaderWidgetAction, showing the specified ``text``. | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsmenuheader.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*************************************************************************** | ||
qgsmenuheader.cpp | ||
----------------- | ||
begin : June 2017 | ||
copyright : (C) 2017 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 "qgsmenuheader.h" | ||
#include <QPainter> | ||
#include <QApplication> | ||
|
||
#define LABEL_SIZE 20 //label rect height | ||
#define LABEL_MARGIN 4 //spacing between label box and text | ||
|
||
QgsMenuHeader::QgsMenuHeader( const QString &text, QWidget *parent ) | ||
: QWidget( parent ) | ||
, mText( text ) | ||
{ | ||
int textMinWidth = fontMetrics().width( mText ); | ||
mMinWidth = 2 * LABEL_MARGIN + textMinWidth; | ||
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); | ||
updateGeometry(); | ||
} | ||
|
||
QSize QgsMenuHeader::minimumSizeHint() const | ||
{ | ||
return QSize( mMinWidth, LABEL_SIZE ); | ||
} | ||
|
||
QSize QgsMenuHeader::sizeHint() const | ||
{ | ||
return QSize( mMinWidth, LABEL_SIZE ); | ||
} | ||
|
||
void QgsMenuHeader::paintEvent( QPaintEvent * ) | ||
{ | ||
QPainter painter( this ); | ||
QPalette pal = QPalette( qApp->palette() ); | ||
QColor headerBgColor = pal.color( QPalette::Mid ); | ||
QColor headerTextColor = pal.color( QPalette::BrightText ); | ||
|
||
//draw header background | ||
painter.setBrush( headerBgColor ); | ||
painter.setPen( Qt::NoPen ); | ||
painter.drawRect( QRect( 0, 0, width(), LABEL_SIZE ) ); | ||
|
||
//draw header text | ||
painter.setPen( headerTextColor ); | ||
painter.drawText( QRect( LABEL_MARGIN, 0, width() - 2 * LABEL_MARGIN, LABEL_SIZE ), | ||
Qt::AlignLeft | Qt::AlignVCenter, mText ); | ||
painter.end(); | ||
} | ||
|
||
QgsMenuHeaderWidgetAction::QgsMenuHeaderWidgetAction( const QString &text, QObject *parent ) | ||
: QWidgetAction( parent ) | ||
{ | ||
QgsMenuHeader *w = new QgsMenuHeader( text, nullptr ); | ||
setDefaultWidget( w ); //transfers ownership | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/*************************************************************************** | ||
qgsmenuheader.h | ||
--------------- | ||
begin : June 2017 | ||
copyright : (C) 2017 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 QGSMENUHEADER_H | ||
#define QGSMENUHEADER_H | ||
|
||
#include <QWidget> | ||
#include <QWidgetAction> | ||
#include "qgis_gui.h" | ||
#include "qgis.h" | ||
|
||
/** \ingroup gui | ||
* \class QgsMenuHeader | ||
* Custom widget for displaying subheaders within a QMenu in a standard style. | ||
* \since QGIS 3.0 | ||
* \see QgsMenuHeaderWidgetAction() | ||
*/ | ||
class GUI_EXPORT QgsMenuHeader : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsMenuHeader, showing the specified \a text. | ||
*/ | ||
explicit QgsMenuHeader( const QString &text, QWidget *parent SIP_TRANSFERTHIS = nullptr ); | ||
|
||
virtual QSize minimumSizeHint() const override; | ||
virtual QSize sizeHint() const override; | ||
|
||
protected: | ||
|
||
void paintEvent( QPaintEvent *event ) override; | ||
|
||
private: | ||
int mMinWidth = 0; | ||
QString mText; | ||
|
||
}; | ||
|
||
/** \ingroup gui | ||
* \class QgsMenuHeader | ||
* Custom QWidgetAction for displaying subheaders within a QMenu in a standard style. | ||
* \since QGIS 3.0 | ||
* \see QgsMenuHeader() | ||
*/ | ||
class GUI_EXPORT QgsMenuHeaderWidgetAction: public QWidgetAction | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsMenuHeaderWidgetAction, showing the specified \a text. | ||
*/ | ||
QgsMenuHeaderWidgetAction( const QString &text, QObject *parent = nullptr ); | ||
|
||
}; | ||
|
||
#endif //QGSMENUHEADER_H |