[kde-doc-english] [trojita] src/Gui: GUI: use LineEdit in the MessageListWidget
Jan Kundrát
jkt at flaska.net
Wed Mar 20 00:39:46 UTC 2013
Git commit 5ad513d10049f484bad1a7a7c15c0520f1d9af3b by Jan Kundrát, on behalf of Glad Deschrijver.
Committed on 20/03/2013 at 00:34.
Pushed by jkt into branch 'master'.
GUI: use LineEdit in the MessageListWidget
M +33 -36 src/Gui/LineEdit.cpp
M +9 -11 src/Gui/LineEdit.h
M +4 -2 src/Gui/MessageListWidget.cpp
M +2 -2 src/Gui/MessageListWidget.h
http://commits.kde.org/trojita/5ad513d10049f484bad1a7a7c15c0520f1d9af3b
diff --git a/src/Gui/LineEdit.cpp b/src/Gui/LineEdit.cpp
index 364f351..2ae1a0b 100644
--- a/src/Gui/LineEdit.cpp
+++ b/src/Gui/LineEdit.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (c) 2007 Trolltech ASA <info at trolltech.com>
-** Modified (c) 2009, 2011 by Glad Deschrijver <glad.deschrijver at gmail.com>
+** Modified (c) 2009, 2011, 2013 by Glad Deschrijver <glad.deschrijver at gmail.com>
**
** Use, modification and distribution is allowed without limitation,
** warranty, liability or support of any kind.
@@ -10,64 +10,61 @@
#include "LineEdit.h"
+#include <QHBoxLayout>
#include <QToolButton>
#include <QStyle>
LineEdit::LineEdit(const QString &text, QWidget *parent)
: QLineEdit(parent)
{
- init();
- setText(text);
+ init();
+ setText(text);
}
LineEdit::LineEdit(QWidget *parent)
: QLineEdit(parent)
{
- init();
+ init();
}
void LineEdit::init()
{
- m_clearButton = new QToolButton(this);
- const QPixmap pixmap(QLatin1String(":/icons/edit-clear-locationbar-rtl.png"));
- m_clearButton->setIcon(QIcon(pixmap));
- m_clearButton->setIconSize(pixmap.size());
- m_clearButton->setCursor(Qt::ArrowCursor);
- m_clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
- m_clearButton->setToolTip(tr("Clear input field"));
- m_clearButton->setFocusPolicy(Qt::NoFocus);
- m_clearButton->hide();
- connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear()));
- connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButton(QString)));
- const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
-// setStyleSheet(QString("QLineEdit { padding-right: %1px; width: %2px; height: %3px; }")
-// .arg(m_clearButton->sizeHint().width() + frameWidth + 1)
-// .arg(sizeHint().width())
-// .arg(sizeHint().height()));
- setStyleSheet(QString("QLineEdit { padding-right: %1px; }")
- .arg(m_clearButton->sizeHint().width() + frameWidth + 1));
-// QSize msz = minimumSizeHint();
-// setMinimumSize(qMax(msz.width(), m_clearButton->sizeHint().height() + frameWidth * 2 + 2),
-// qMax(msz.height(), m_clearButton->sizeHint().height() + frameWidth * 2 + 2));
+ m_clearButton = new QToolButton(this);
+ const QPixmap pixmap(QLatin1String(":/icons/edit-clear-locationbar-rtl.png"));
+ m_clearButton->setIcon(QIcon(pixmap));
+ m_clearButton->setIconSize(pixmap.size());
+ m_clearButton->setCursor(Qt::ArrowCursor);
+ m_clearButton->setToolTip(tr("Clear input field"));
+ m_clearButton->setFocusPolicy(Qt::NoFocus);
+ m_clearButton->hide();
+ connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear()));
+ connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButton(QString)));
+
+ const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ m_clearButton->setStyleSheet(QString("QToolButton { border: none; padding-left: 1px; padding-top: %1px; padding-bottom: %1px; padding-right: %1px; }")
+ .arg(frameWidth + 1));
+ setStyleSheet(QString("QLineEdit { padding-right: %1px; }")
+ .arg(m_clearButton->sizeHint().width()));
+
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addStretch();
+ layout->addWidget(m_clearButton);
}
-QSize LineEdit::sizeHint() const
+QToolButton *LineEdit::clearButton()
{
- const QSize msz = QLineEdit::sizeHint();
- const int minimumHeight = m_clearButton->sizeHint().height() + style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2;
- return QSize(qMax(msz.width(), minimumHeight + 2), qMax(msz.height(), minimumHeight));
+ return m_clearButton;
}
-void LineEdit::resizeEvent(QResizeEvent *event)
+QSize LineEdit::sizeHint() const
{
- const QSize sz = m_clearButton->sizeHint();
- const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- m_clearButton->move(rect().right() - frameWidth - sz.width(),
- (rect().bottom() + 1 - sz.height()) / 2);
- QLineEdit::resizeEvent(event);
+ const QSize defaultSize = QLineEdit::sizeHint();
+ const int minimumWidth = m_clearButton->sizeHint().width() + 2;
+ return QSize(qMax(defaultSize.width(), minimumWidth), defaultSize.height());
}
void LineEdit::updateClearButton(const QString &text)
{
- m_clearButton->setVisible(!text.isEmpty());
+ m_clearButton->setVisible(!text.isEmpty());
}
diff --git a/src/Gui/LineEdit.h b/src/Gui/LineEdit.h
index c4e7e77..1cb5212 100644
--- a/src/Gui/LineEdit.h
+++ b/src/Gui/LineEdit.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (c) 2007 Trolltech ASA <info at trolltech.com>
-** Modified (c) 2009, 2011 by Glad Deschrijver <glad.deschrijver at gmail.com>
+** Modified (c) 2009, 2011, 2013 by Glad Deschrijver <glad.deschrijver at gmail.com>
**
** Use, modification and distribution is allowed without limitation,
** warranty, liability or support of any kind.
@@ -17,23 +17,21 @@ class QToolButton;
class LineEdit : public QLineEdit
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit LineEdit(const QString &text, QWidget *parent = 0);
- LineEdit(QWidget *parent = 0);
- virtual QSize sizeHint() const;
-
-protected:
- void resizeEvent(QResizeEvent *event);
+ explicit LineEdit(const QString &text, QWidget *parent = 0);
+ LineEdit(QWidget *parent = 0);
+ QToolButton *clearButton();
+ virtual QSize sizeHint() const;
private Q_SLOTS:
- void updateClearButton(const QString &text);
+ void updateClearButton(const QString &text);
private:
- void init();
+ void init();
- QToolButton *m_clearButton;
+ QToolButton *m_clearButton;
};
#endif // LINEEDIT_H
diff --git a/src/Gui/MessageListWidget.cpp b/src/Gui/MessageListWidget.cpp
index 8391978..2fb2915 100644
--- a/src/Gui/MessageListWidget.cpp
+++ b/src/Gui/MessageListWidget.cpp
@@ -25,13 +25,13 @@
#include <QApplication>
#include <QCheckBox>
#include <QFrame>
-#include <QLineEdit>
#include <QMenu>
#include <QTimer>
#include <QToolButton>
#include <QVBoxLayout>
#include <QWidgetAction>
#include "IconLoader.h"
+#include "LineEdit.h"
#include "MsgListView.h"
namespace Gui {
@@ -41,7 +41,7 @@ MessageListWidget::MessageListWidget(QWidget *parent) :
{
tree = new MsgListView(this);
- m_quickSearchText = new QLineEdit(this);
+ m_quickSearchText = new LineEdit(this);
#if QT_VERSION >= 0x040700
m_quickSearchText->setPlaceholderText(tr("Quick Search / Leading \":=\" for direct IMAP search"));
#endif
@@ -94,10 +94,12 @@ MessageListWidget::MessageListWidget(QWidget *parent) :
m_searchOptions->setMenu(optionsMenu);
connect (optionsMenu, SIGNAL(aboutToShow()), SLOT(slotDeActivateSimpleSearch()));
+ delete m_quickSearchText->layout();
QHBoxLayout *hlayout = new QHBoxLayout(m_quickSearchText);
hlayout->setContentsMargins(0, 0, 0, 0);
hlayout->addWidget(m_searchOptions);
hlayout->addStretch();
+ hlayout->addWidget(m_quickSearchText->clearButton());
hlayout->activate(); // this processes the layout and ensures the toolbutton has it's final dimensions
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
if (QGuiApplication::isLeftToRight())
diff --git a/src/Gui/MessageListWidget.h b/src/Gui/MessageListWidget.h
index 15d3c80..744a47d 100644
--- a/src/Gui/MessageListWidget.h
+++ b/src/Gui/MessageListWidget.h
@@ -25,7 +25,7 @@
#include <QWidget>
-class QLineEdit;
+class LineEdit;
class QTimer;
class QToolButton;
@@ -63,7 +63,7 @@ private slots:
void slotUpdateSearchCursor();
private:
- QLineEdit *m_quickSearchText;
+ LineEdit *m_quickSearchText;
QToolButton *m_searchOptions;
QAction *m_searchInSubject;
QAction *m_searchInBody;
More information about the kde-doc-english
mailing list