Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

implement clear button for translateLine #113

Open
wants to merge 2 commits into from

3 participants

@zdenop

for me clear button increase productivity

@zdenop

Is there any problem with this pull request/feature?

@Tvangeste
Owner

Actually, we already have a fully-featured ExtLineEdit that supports buttons on both sides of the line edit, even with autohide. In couple of places we already use clear button (in search fields in the Dictionary preferences).

The problem is that for the main translate line the right side is already taken (to provide a handle to open a suggestion list), at least in the new UI.

So it seems that we might need two buttons there, one to open a suggestion list and another one to clear the field.

@Tvangeste
Owner

Also, there is a rather old experimental branch by @dragonroot with some similar functionality.

Just in case: https://github.com/goldendict/goldendict/tree/kde-style-line-edit

But I think that the ExtLineEdit is a good start to look at and maybe to provide this capability to have multiple icons/buttons on both sides.

And I'm sorry that I missed your pull request earlier.

@dragonroot
Owner

That branch of mine was never merged since that implementation had problems. I don't remember exactly what sort of problems those were - probably something look&feel related. It never got merged since the problems were grave enough not to warrant the feature at all. Maybe the implementation in this pull request is better - I haven't tried it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 16, 2012
  1. @zdenop
  2. @zdenop

    improve button position

    zdenop authored
This page is out of date. Refresh to see the latest.
View
6 goldendict.pro
@@ -200,7 +200,8 @@ HEADERS += folding.hh \
sdict.hh \
decompress.hh \
aard.hh \
- mruqmenu.hh
+ mruqmenu.hh \
+ lineedit.hh
FORMS += groups.ui \
dictgroupwidget.ui \
mainwindow.ui \
@@ -293,7 +294,8 @@ SOURCES += folding.cc \
sdict.cc \
decompress.cc \
aard.cc \
- mruqmenu.cc
+ mruqmenu.cc \
+ lineedit.cc
win32 {
SOURCES += mouseover_win32/ThTypes.c \
wordbyauto.cc \
View
BIN  icons/fileclose.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
53 lineedit.cc
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** 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.hh"
+#include <QToolButton>
+#include <QStyle>
+
+LineEdit::LineEdit(QWidget *parent)
+ : QLineEdit(parent)
+{
+ clearButton = new QToolButton(this);
+ QPixmap pixmap( ":/icons/fileclose.png" );
+ clearButton->setIcon( QIcon(pixmap) );
+ clearButton->setIconSize( pixmap.size() );
+ clearButton->setCursor( Qt::ArrowCursor );
+ clearButton->setStyleSheet( "QToolButton {border: none; padding-top: 2px; \
+ padding-bottom: -2px;}" );
+ 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() );
+}
+
+
View
35 lineedit.hh
@@ -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 LINEEDIT_H
+#define LINEEDIT_H
+
+#include <QLineEdit>
+
+class QToolButton;
+
+class LineEdit : public QLineEdit
+{
+ Q_OBJECT
+
+public:
+ LineEdit( QWidget *parent = 0 );
+
+protected:
+ void resizeEvent( QResizeEvent * );
+
+private slots:
+ void updateCloseButton( const QString &text );
+
+private:
+ QToolButton *clearButton;
+};
+
+#endif // LINEEDIT_H
+
View
1  main.cc
@@ -5,6 +5,7 @@
#include <QIcon>
#include "gdappstyle.hh"
#include "mainwindow.hh"
+#include "lineedit.hh"
#include "config.hh"
#include "processwrapper.hh"
View
7 mainwindow.ui
@@ -153,7 +153,7 @@
<number>1</number>
</property>
<item>
- <widget class="QLineEdit" name="translateLine">
+ <widget class="LineEdit" name="translateLine">
<property name="minimumSize">
<size>
<width>200</width>
@@ -443,6 +443,11 @@
<header>maintabwidget.hh</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>LineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>lineedit.hh</header>
+ </customwidget>
</customwidgets>
<tabstops>
<tabstop>translateLine</tabstop>
View
1  resources.qrc
@@ -27,6 +27,7 @@
<file>icons/icon32_hunspell.png</file>
<file>icons/fileopen.png</file>
<file>icons/filesave.png</file>
+ <file>icons/fileclose.png</file>
<file>icons/icon32_wiki.png</file>
<file>icons/icon32_zoombase.png</file>
<file>icons/icon32_zoomin.png</file>
Something went wrong with that request. Please try again.