10#include "MarbleLineEdit.h"
11#include "MarbleGlobal.h"
13#include <QApplication>
24class MarbleLineEditPrivate
43 explicit MarbleLineEditPrivate( MarbleLineEdit* parent );
45 void createProgressAnimation();
48MarbleLineEditPrivate::MarbleLineEditPrivate( MarbleLineEdit* parent ) :
49 m_clearButton( new
QLabel( parent ) ), m_decoratorButton( new
QLabel( parent ) ),
50 m_currentFrame( 0 ), m_iconSize( 16 )
53 m_clearButton->setToolTip(
QObject::tr(
"Clear" ) );
55 createProgressAnimation();
56 m_progressTimer.setInterval( 100 );
57 if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
62void MarbleLineEditPrivate::createProgressAnimation()
65 qreal
const h = m_iconSize / 2.0;
66 qreal
const q = h / 2.0;
68 qreal
const r = d / 2.0;
78 for(
double t = 0.0; t < 2 * M_PI; t += M_PI / 8.0 ) {
80 QRectF firstCircle( h - r + q * cos( t ), h - r + q * sin( t ), d, d );
81 QRectF secondCircle( h - r + q * cos( t + M_PI ), h - r + q * sin( t + M_PI ), d, d );
82 painter.drawEllipse( firstCircle );
83 painter.drawEllipse( secondCircle );
88MarbleLineEdit::MarbleLineEdit(
QWidget *parent ) :
89 QLineEdit( parent ), d( new MarbleLineEditPrivate( this ) )
91 updateClearButtonIcon(
text() );
94 setDecorator( d->m_decoratorPixmap );
96 SLOT(updateClearButtonIcon(
QString)) );
97 connect( &d->m_progressTimer, SIGNAL(timeout()),
98 this, SLOT(updateProgress()) );
106void MarbleLineEdit::setDecorator(
const QPixmap &decorator)
108 d->m_decoratorPixmap = decorator;
109 d->m_decoratorButton->setPixmap( d->m_decoratorPixmap );
110 int const padding = 2 + d->m_decoratorPixmap.width();
114 if ( !d->m_decoratorPixmap.isNull() ) {
115 decoratorStyleSheet =
QString(
"; padding-%1: %2" ).
arg( prefixDirection ).
arg( padding );
121 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
122 if ( !smallScreen ) {
127void MarbleLineEdit::setBusy(
bool busy)
130 d->m_progressTimer.start();
132 d->m_progressTimer.stop();
133 d->m_decoratorButton->setPixmap( d->m_decoratorPixmap );
137void MarbleLineEdit::updateClearButtonIcon(
const QString& text )
139 d->m_clearButton->setVisible(
text.length() > 0 );
140 if ( d->m_clearButton->pixmap() && !d->m_clearButton->pixmap()->isNull() ) {
145 int const size = (MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen) ? 32 : 16;
146 QPixmap pixmap =
QPixmap(QStringLiteral(
":/icons/%1x%1/edit-clear-locationbar-%2.png").arg(
size).arg(direction));
147 d->m_clearButton->setPixmap( pixmap );
150void MarbleLineEdit::updateClearButton()
154 const int pixmapSize = d->m_clearButton->pixmap()->width() + 1;
155 const int decoratorSize = d->m_decoratorPixmap.width() + 1;
157 int y = ( geom.
height() - pixmapSize ) / 2;
159 d->m_clearButton->move( geom.
width() - frameWidth - pixmapSize - decoratorSize,
y );
160 d->m_decoratorButton->move( frameWidth - decoratorSize + 1,
y );
162 d->m_clearButton->move( frameWidth - decoratorSize + 1,
y );
163 d->m_decoratorButton->move( geom.
width() - frameWidth - pixmapSize - decoratorSize,
y );
167void MarbleLineEdit::updateProgress()
169 if ( !d->m_progressAnimation.isEmpty() ) {
170 d->m_currentFrame = ( d->m_currentFrame + 1 ) % d->m_progressAnimation.size();
171 QPixmap frame = d->m_progressAnimation[d->m_currentFrame];
172 d->m_decoratorButton->setPixmap(
frame );
176void MarbleLineEdit::mouseReleaseEvent(
QMouseEvent* e )
178 if ( d->m_clearButton ==
childAt( e->
pos() ) ) {
191 if ( d->m_decoratorButton ==
childAt( e->
pos() ) ) {
192 emit decoratorButtonClicked();
206#include "moc_MarbleLineEdit.cpp"
void clearButtonClicked()
The clear button was clicked with the left mouse button.
~MarbleLineEdit() override
Destructor.
Binds a QML item to a specific geodetic location in screen coordinates.
QString text(Mode mode) const const
virtual bool event(QEvent *e) override
virtual void mouseReleaseEvent(QMouseEvent *e) override
void setSelection(int start, int length)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString tr(const char *sourceText, const char *disambiguation, int n)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
QString arg(Args &&... args) const const
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const const=0