mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-12 15:59:58 -05:00
Add line edit widget with integrated clear button.
This commit is contained in:
parent
3be90b02d6
commit
e5e7e5e406
Binary file not shown.
After Width: | Height: | Size: 750 B |
@ -64,6 +64,7 @@ set(keepassx_SOURCES
|
|||||||
gui/FileDialog.cpp
|
gui/FileDialog.cpp
|
||||||
gui/IconModels.cpp
|
gui/IconModels.cpp
|
||||||
gui/KeePass1OpenDialog.cpp
|
gui/KeePass1OpenDialog.cpp
|
||||||
|
gui/LineEdit.cpp
|
||||||
gui/MainWindow.cpp
|
gui/MainWindow.cpp
|
||||||
gui/entry/EditEntryWidget.cpp
|
gui/entry/EditEntryWidget.cpp
|
||||||
gui/entry/EntryAttachmentsModel.cpp
|
gui/entry/EntryAttachmentsModel.cpp
|
||||||
@ -102,6 +103,7 @@ set(keepassx_MOC
|
|||||||
gui/EditWidget.h
|
gui/EditWidget.h
|
||||||
gui/EditWidgetIcons.h
|
gui/EditWidgetIcons.h
|
||||||
gui/IconModels.h
|
gui/IconModels.h
|
||||||
|
gui/LineEdit.h
|
||||||
gui/MainWindow.h
|
gui/MainWindow.h
|
||||||
gui/entry/EditEntryWidget.h
|
gui/entry/EditEntryWidget.h
|
||||||
gui/entry/EntryAttachmentsModel.h
|
gui/entry/EntryAttachmentsModel.h
|
||||||
|
50
src/gui/LineEdit.cpp
Normal file
50
src/gui/LineEdit.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
|
||||||
|
**
|
||||||
|
** Use, modification and distribution is allowed without limitation,
|
||||||
|
** warranty, liability or support of any kind.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "LineEdit.h"
|
||||||
|
|
||||||
|
#include <QtGui/QToolButton>
|
||||||
|
#include <QtGui/QStyle>
|
||||||
|
|
||||||
|
#include "core/DataPath.h"
|
||||||
|
|
||||||
|
LineEdit::LineEdit(QWidget* parent)
|
||||||
|
: QLineEdit(parent)
|
||||||
|
{
|
||||||
|
clearButton = new QToolButton(this);
|
||||||
|
clearButton->setObjectName("clearButton");
|
||||||
|
QIcon icon = dataPath()->icon("action", "edit-clear-locationbar-rtl");
|
||||||
|
clearButton->setIcon(icon);
|
||||||
|
clearButton->setCursor(Qt::ArrowCursor);
|
||||||
|
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||||
|
clearButton->hide();
|
||||||
|
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
|
||||||
|
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
|
||||||
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
|
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ")
|
||||||
|
.arg(clearButton->sizeHint().width() + frameWidth + 1));
|
||||||
|
QSize msz = minimumSizeHint();
|
||||||
|
setMinimumSize(qMax(msz.width(), clearButton->sizeHint().height() + frameWidth * 2 + 2),
|
||||||
|
qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineEdit::resizeEvent(QResizeEvent*)
|
||||||
|
{
|
||||||
|
QSize sz = clearButton->sizeHint();
|
||||||
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
|
clearButton->move(rect().right() - frameWidth - sz.width(),
|
||||||
|
(rect().bottom() + 1 - sz.height())/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineEdit::updateCloseButton(const QString& text)
|
||||||
|
{
|
||||||
|
clearButton->setVisible(!text.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
35
src/gui/LineEdit.h
Normal file
35
src/gui/LineEdit.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
|
||||||
|
**
|
||||||
|
** Use, modification and distribution is allowed without limitation,
|
||||||
|
** warranty, liability or support of any kind.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef KEEPASSX_LINEEDIT_H
|
||||||
|
#define KEEPASSX_LINEEDIT_H
|
||||||
|
|
||||||
|
#include <QtGui/QLineEdit>
|
||||||
|
|
||||||
|
class QToolButton;
|
||||||
|
|
||||||
|
class LineEdit : public QLineEdit
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
LineEdit(QWidget* parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent*);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void updateCloseButton(const QString& text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QToolButton* clearButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KEEPASSX_LINEEDIT_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user