Added icon-based feedback for InputField

This commit is contained in:
Yorik van Havre 2014-01-15 11:48:16 -02:00
parent 5556d1506e
commit 0b945388ea
5 changed files with 172 additions and 7 deletions

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16px"
height="16px"
id="svg2985"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="button_invalid.svg"
inkscape:export-filename="/home/yorik/Sources/FreeCAD/src/Gui/Icons/button_invalid.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs2987" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="22.197802"
inkscape:cx="0.83712865"
inkscape:cy="8"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:grid-bbox="true"
inkscape:document-units="px"
inkscape:window-width="1360"
inkscape:window-height="741"
inkscape:window-x="1920"
inkscape:window-y="0"
inkscape:window-maximized="1" />
<metadata
id="metadata2990">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
style="color:#000000;fill:#da0d06;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 7.9237004,2.087937 c -2.4640917,0 -4.4642325,1.9813835 -4.4642325,4.4454751 0,2.4640919 2.0001408,4.4642329 4.4642325,4.4642329 2.4640916,0 4.4642316,-2.000141 4.4642316,-4.4642329 0,-2.4640916 -2.00014,-4.4454751 -4.4642316,-4.4454751 z m 0,1.4255532 c 1.6725948,0 3.0386786,1.3473264 3.0386786,3.0199219 0,1.6725955 -1.3660838,3.0386798 -3.0386786,3.0386798 -1.6725956,0 -3.019922,-1.3660843 -3.019922,-3.0386798 0,-1.6725955 1.3473264,-3.0199219 3.019922,-3.0199219 z"
id="path2993"
inkscape:connector-curvature="0" />
<rect
style="color:#000000;fill:#da0d06;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect3828"
width="7.2738128"
height="1.7305728"
x="-3.3377991"
y="9.4661617"
transform="matrix(0.6651899,-0.74667423,0.74667423,0.6651899,0,0)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16px"
height="16px"
id="svg2985"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="button_valid.svg">
<defs
id="defs2987" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="22.197802"
inkscape:cx="0.83712865"
inkscape:cy="8"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:grid-bbox="true"
inkscape:document-units="px"
inkscape:window-width="1360"
inkscape:window-height="741"
inkscape:window-x="1920"
inkscape:window-y="0"
inkscape:window-maximized="1" />
<metadata
id="metadata2990">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
style="color:#000000;fill:#01b600;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 8.0464728,1.9753095 c -2.4267933,0 -4.3966584,1.9698651 -4.3966584,4.3966584 0,2.4267936 1.9698651,4.3966591 4.3966584,4.3966591 2.4267932,0 4.3966582,-1.9698655 4.3966582,-4.3966591 0,-1.0385761 -0.376643,-2.0004518 -0.979088,-2.7525298 L 6.7718113,10.454579 3.9638614,5.023413 6.7718113,7.2956358 11.168469,3.2869176 C 10.371827,2.4804217 9.2696445,1.9753095 8.0464728,1.9753095 z"
id="path2993"
inkscape:connector-curvature="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -14,6 +14,8 @@
<file>button_left.svg</file>
<file>button_right.svg</file>
<file>button_up.svg</file>
<file>button_valid.svg</file>
<file>button_invalid.svg</file>
<file>macro-execute.svg</file>
<file>macro-record.svg</file>
<file>macro-stop.svg</file>

View File

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (c) 2013 Juergen Riegel *
* Copyright (c) 2013 Juergen Riegel *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@ -33,6 +33,7 @@
#include <App/Application.h>
#include "InputField.h"
#include "BitmapFactory.h"
using namespace Gui;
using namespace Base;
@ -47,6 +48,19 @@ InputField::InputField ( QWidget * parent )
HistorySize(5),
SaveSize(5)
{
iconLabel = new QLabel(this);
iconLabel->setCursor(Qt::ArrowCursor);
QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_valid.svg", QSize(sizeHint().height(),sizeHint().height()));
iconLabel->setPixmap(pixmap);
iconLabel->setStyleSheet(QString::fromAscii("QLabel { border: none; padding: 0px; }"));
iconLabel->hide();
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateIconLabel(const QString&)));
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
setStyleSheet(QString::fromAscii("QLineEdit { padding-right: %1px } ").arg(iconLabel->sizeHint().width() + frameWidth + 1));
QSize msz = minimumSizeHint();
setMinimumSize(qMax(msz.width(), iconLabel->sizeHint().height() + frameWidth * 2 + 2),
qMax(msz.height(), iconLabel->sizeHint().height() + frameWidth * 2 + 2));
this->setContextMenuPolicy(Qt::DefaultContextMenu);
QObject::connect(this, SIGNAL(textChanged (QString)),
@ -57,6 +71,19 @@ InputField::~InputField()
{
}
void InputField::resizeEvent(QResizeEvent *)
{
QSize sz = iconLabel->sizeHint();
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
iconLabel->move(rect().right() - frameWidth - sz.width(),
(rect().bottom() + 1 - sz.height())/2);
}
void InputField::updateIconLabel(const QString& text)
{
iconLabel->setVisible(!text.isEmpty());
}
void InputField::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *editMenu = createStandardContextMenu();
@ -112,15 +139,15 @@ void InputField::newInput(const QString & text)
}catch(Base::Exception &e){
ErrorText = e.what();
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
QPalette palette;
palette.setColor(QPalette::Base,QColor(255,200,200));
setPalette(palette);
QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_invalid.svg", QSize(sizeHint().height(),sizeHint().height()));
iconLabel->setPixmap(pixmap);
parseError(QString::fromAscii(ErrorText.c_str()));
return;
}
QPalette palette;
palette.setColor(QPalette::Base,QColor(200,255,200));
setPalette(palette);
QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_valid.svg", QSize(sizeHint().height(),sizeHint().height()));
iconLabel->setPixmap(pixmap);
ErrorText = "";
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
actQuantity = res;

View File

@ -128,12 +128,15 @@ Q_SIGNALS:
protected Q_SLOTS:
void newInput(const QString & text);
void updateIconLabel(const QString& text);
void wheelEvent ( QWheelEvent * event ) ;
protected:
virtual void contextMenuEvent ( QContextMenuEvent * event );
virtual void resizeEvent(QResizeEvent*);
private:
QLabel* iconLabel;
QByteArray m_sPrefGrp;
std::string ErrorText;