QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsmenuheader.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsmenuheader.cpp
3
-----------------
4
begin : June 2017
5
copyright : (C) 2017 by Nyall Dawson
6
email : nyall dot dawson at gmail dot com
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgsmenuheader.h
"
19
20
#include "
qgis.h
"
21
22
#include <QApplication>
23
#include <QPainter>
24
25
#include "moc_qgsmenuheader.cpp"
26
27
QgsMenuHeader::QgsMenuHeader
(
const
QString &text, QWidget *parent )
28
: QWidget( parent )
29
, mText( text )
30
{
31
const
int
textMinWidth = fontMetrics().boundingRect( mText ).width();
32
mTextHeight = fontMetrics().height();
33
mLabelMargin =
Qgis::UI_SCALE_FACTOR
* fontMetrics().horizontalAdvance(
'.'
);
34
mMinWidth = 2 * mLabelMargin + textMinWidth;
35
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
36
updateGeometry();
37
}
38
39
QSize
QgsMenuHeader::minimumSizeHint
()
const
40
{
41
return
QSize( mMinWidth, mTextHeight + mLabelMargin );
42
}
43
44
QSize
QgsMenuHeader::sizeHint
()
const
45
{
46
return
QSize( mMinWidth, mTextHeight + mLabelMargin );
47
}
48
49
void
QgsMenuHeader::paintEvent
( QPaintEvent * )
50
{
51
QPainter painter(
this
);
52
const
QPalette
pal
= QPalette( qApp->palette() );
53
const
QColor headerBgColor =
pal
.color( QPalette::Mid );
54
const
QColor headerTextColor =
pal
.color( QPalette::BrightText );
55
56
//draw header background
57
painter.setBrush( headerBgColor );
58
painter.setPen( Qt::NoPen );
59
painter.drawRect( QRect( 0, 0, width(), mTextHeight + mLabelMargin ) );
60
61
//draw header text
62
painter.setPen( headerTextColor );
63
painter.drawText( QPoint( mLabelMargin, 0.25 * mLabelMargin + mTextHeight ), mText );
64
painter.end();
65
}
66
67
QgsMenuHeaderWidgetAction::QgsMenuHeaderWidgetAction
(
const
QString &text, QObject *parent )
68
: QWidgetAction( parent )
69
{
70
QgsMenuHeader
*w =
new
QgsMenuHeader
( text,
nullptr
);
71
setDefaultWidget( w );
//transfers ownership
72
}
Qgis::UI_SCALE_FACTOR
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition
qgis.h:7338
QgsMenuHeaderWidgetAction::QgsMenuHeaderWidgetAction
QgsMenuHeaderWidgetAction(const QString &text, QObject *parent=nullptr)
Constructor for QgsMenuHeaderWidgetAction, showing the specified text.
Definition
qgsmenuheader.cpp:67
QgsMenuHeader
Custom widget for displaying subheaders within a QMenu in a standard style.
Definition
qgsmenuheader.h:33
QgsMenuHeader::paintEvent
void paintEvent(QPaintEvent *event) override
Definition
qgsmenuheader.cpp:49
QgsMenuHeader::QgsMenuHeader
QgsMenuHeader(const QString &text, QWidget *parent=nullptr)
Constructor for QgsMenuHeader, showing the specified text.
Definition
qgsmenuheader.cpp:27
QgsMenuHeader::sizeHint
QSize sizeHint() const override
Definition
qgsmenuheader.cpp:44
QgsMenuHeader::minimumSizeHint
QSize minimumSizeHint() const override
Definition
qgsmenuheader.cpp:39
pal
Definition
qgsdiagramrenderer.h:51
qgis.h
qgsmenuheader.h
Generated on
for QGIS API Documentation by
1.17.0