QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsstatusbar.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsstatusbar.cpp
3
----------------
4
begin : May 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 "
qgsstatusbar.h
"
19
20
#include "
qgsapplication.h
"
21
22
#include <QEvent>
23
#include <QLayout>
24
#include <QLineEdit>
25
#include <QPalette>
26
#include <QStatusBar>
27
#include <QString>
28
#include <QTimer>
29
30
#include "moc_qgsstatusbar.cpp"
31
32
using namespace
Qt::StringLiterals;
33
34
QgsStatusBar::QgsStatusBar
( QWidget *parent )
35
: QWidget( parent )
36
{
37
mLayout =
new
QHBoxLayout();
38
mLayout->setContentsMargins( 2, 0, 2, 0 );
39
mLayout->setSpacing( 6 );
40
41
mLineEdit =
new
QLineEdit( QString() );
42
mLineEdit->setDisabled(
true
);
43
mLineEdit->setFrame(
false
);
44
mLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
45
applyWidgetStyle();
46
mLayout->addWidget( mLineEdit, 10 );
47
setLayout( mLayout );
48
49
connect(
QgsApplication::instance
(), &
QgsApplication::themeChanged
,
this
, &QgsStatusBar::applyWidgetStyle );
50
}
51
52
void
QgsStatusBar::applyWidgetStyle()
53
{
54
QPalette
pal
= mLineEdit->palette();
55
pal
.setColor( QPalette::Disabled, QPalette::Text, palette().color( QPalette::WindowText ) );
56
mLineEdit->setPalette(
pal
);
57
mLineEdit->setStyleSheet( u
"* { border: 0; background-color: rgba(0, 0, 0, 0); color: %1; }"
_s.arg( palette().color( QPalette::WindowText ).name() ) );
58
}
59
60
void
QgsStatusBar::addPermanentWidget
( QWidget *widget,
int
stretch,
Anchor
anchor )
61
{
62
switch
( anchor )
63
{
64
case
AnchorLeft
:
65
mLayout->insertWidget( 0, widget, stretch, Qt::AlignLeft );
66
break
;
67
68
case
AnchorRight
:
69
mLayout->addWidget( widget, stretch, Qt::AlignLeft );
70
break
;
71
}
72
}
73
74
void
QgsStatusBar::removeWidget
( QWidget *widget )
75
{
76
mLayout->removeWidget( widget );
77
widget->hide();
78
}
79
80
QString
QgsStatusBar::currentMessage
()
const
81
{
82
return
mLineEdit->text();
83
}
84
85
void
QgsStatusBar::showMessage
(
const
QString &text,
int
timeout )
86
{
87
mLineEdit->setText( text );
88
mLineEdit->setCursorPosition( 0 );
89
if
( timeout > 0 )
90
{
91
if
( !mTempMessageTimer )
92
{
93
mTempMessageTimer =
new
QTimer(
this
);
94
connect( mTempMessageTimer, &QTimer::timeout,
this
, &
QgsStatusBar::clearMessage
);
95
mTempMessageTimer->setSingleShot(
true
);
96
}
97
mTempMessageTimer->start( timeout );
98
}
99
else
if
( mTempMessageTimer )
100
{
101
delete
mTempMessageTimer;
102
mTempMessageTimer =
nullptr
;
103
}
104
}
105
106
void
QgsStatusBar::clearMessage
()
107
{
108
mLineEdit->setText( QString() );
109
}
110
111
void
QgsStatusBar::setParentStatusBar
( QStatusBar *statusBar )
112
{
113
if
( mParentStatusBar )
114
QStatusBar::disconnect( mShowMessageConnection );
115
116
mParentStatusBar = statusBar;
117
118
if
( mParentStatusBar )
119
mShowMessageConnection = connect( mParentStatusBar, &QStatusBar::messageChanged,
this
, [
this
](
const
QString &message ) {
showMessage
( message ); } );
120
}
121
122
void
QgsStatusBar::changeEvent
( QEvent *event )
123
{
124
QWidget::changeEvent( event );
125
126
if
( event->type() == QEvent::FontChange )
127
{
128
mLineEdit->setFont( font() );
129
}
130
}
QgsApplication::themeChanged
void themeChanged()
Emitted when the application theme has changed.
QgsApplication::instance
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
Definition
qgsapplication.cpp:689
QgsStatusBar::Anchor
Anchor
Placement anchor for widgets.
Definition
qgsstatusbar.h:53
QgsStatusBar::AnchorLeft
@ AnchorLeft
Anchor widget to left of status bar.
Definition
qgsstatusbar.h:54
QgsStatusBar::AnchorRight
@ AnchorRight
Anchor widget to right of status bar.
Definition
qgsstatusbar.h:55
QgsStatusBar::clearMessage
void clearMessage()
Removes any temporary message being shown.
Definition
qgsstatusbar.cpp:106
QgsStatusBar::removeWidget
void removeWidget(QWidget *widget)
Removes a widget from the status bar.
Definition
qgsstatusbar.cpp:74
QgsStatusBar::QgsStatusBar
QgsStatusBar(QWidget *parent=nullptr)
Constructor for QgsStatusBar.
Definition
qgsstatusbar.cpp:34
QgsStatusBar::changeEvent
void changeEvent(QEvent *event) override
Definition
qgsstatusbar.cpp:122
QgsStatusBar::addPermanentWidget
void addPermanentWidget(QWidget *widget, int stretch=0, Anchor anchor=AnchorRight)
Adds the given widget permanently to this status bar, reparenting the widget if it isn't already a ch...
Definition
qgsstatusbar.cpp:60
QgsStatusBar::currentMessage
QString currentMessage() const
Returns the current message shown in the status bar.
Definition
qgsstatusbar.cpp:80
QgsStatusBar::setParentStatusBar
void setParentStatusBar(QStatusBar *statusBar)
Sets the parent status bar.
Definition
qgsstatusbar.cpp:111
QgsStatusBar::showMessage
void showMessage(const QString &message, int timeout=0)
Displays the given message for the specified number of milli-seconds (timeout).
Definition
qgsstatusbar.cpp:85
pal
Definition
qgsdiagramrenderer.h:51
qgsapplication.h
qgsstatusbar.h
Generated on
for QGIS API Documentation by
1.17.0