diff --git a/src/Gui/Icons/button_invalid.svg b/src/Gui/Icons/button_invalid.svg new file mode 100644 index 000000000..c481b2f19 --- /dev/null +++ b/src/Gui/Icons/button_invalid.svg @@ -0,0 +1,72 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/Gui/Icons/button_valid.svg b/src/Gui/Icons/button_valid.svg new file mode 100644 index 000000000..b31af57ba --- /dev/null +++ b/src/Gui/Icons/button_valid.svg @@ -0,0 +1,61 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/Gui/Icons/resource.qrc b/src/Gui/Icons/resource.qrc index 133bba4de..dc5128f77 100644 --- a/src/Gui/Icons/resource.qrc +++ b/src/Gui/Icons/resource.qrc @@ -14,6 +14,8 @@ button_left.svg button_right.svg button_up.svg + button_valid.svg + button_invalid.svg macro-execute.svg macro-record.svg macro-stop.svg diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index da71cd953..50df3f4f2 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -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 #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; diff --git a/src/Gui/InputField.h b/src/Gui/InputField.h index 5af5ff5ac..9eec33195 100644 --- a/src/Gui/InputField.h +++ b/src/Gui/InputField.h @@ -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;